Пример #1
0
 public function test_toNull()
 {
     $this->assertNull(Option::none()->toNull());
     $this->assertEquals($this->helloWorld, Option::some($this->helloWorld)->toNull());
 }
Пример #2
0
 /**
  * Returns an optional value that has a value of the given argument if the given boolean is true, otherwise,
  * returns no value
  *
  * @param bool $p
  * @param $value
  * @return Option
  */
 public static function iif(bool $p, $value) : Option
 {
     if ($p == true) {
         return Option::some($value);
     }
     return Option::none();
 }
Пример #3
0
 /**
  * Returns an option containing the result of applying $f to this option's value
  * if it is non-empty
  * 
  * $f should take the wrapped value and return a new value
  */
 public function map(callable $f)
 {
     return !$this->isEmpty() ? Option::just($f($this->get())) : Option::none();
 }