Example #1
0
 /**
  * Tests that the map function will return an instance of None
  * if the callable passed returns None
  */
 public function testMapReturnsAbsentOnAbsent()
 {
     $present = $this->getPresent();
     $mapped = $present->map(function ($string) {
         return Optional::absent();
     });
     $this->assertInstanceOf('Bart\\Optional\\None', $mapped);
 }
Example #2
0
 public function testFromNullable()
 {
     $value = 'box_rox';
     $present = Optional::fromNullable($value);
     $this->assertInstanceOf('Bart\\Optional\\Some', $present);
     $this->assertEquals($value, $present->get());
     $absent = Optional::fromNullable(null);
     $this->assertInstanceOf('Bart\\Optional\\None', $absent);
 }
Example #3
0
 /**
  * Returns an Optional containing the result of calling $callable on
  * the contained value. If no value exists, as in the case of None, then
  * this method will simply return None. The method will return None
  * if the result of applying $callable to the contained value is null.
  * @param callable $callable
  * @return Some|None
  */
 public function map(callable $callable)
 {
     return Optional::absent();
 }