Beispiel #1
0
 /**
  * @test
  */
 public function shouldNegate()
 {
     //given
     $function = FluentFunctions::startsWith("start")->negate();
     //when
     $result = Functions::call($function, "starts with prefix");
     //then
     $this->assertFalse($result);
 }
Beispiel #2
0
 /**
  * @test
  */
 public function shouldReturnOrForAbsentMap()
 {
     //given
     $optional = Optional::fromNullable(null);
     $closure = FluentFunctions::extractField('myField')->append('!!!');
     //when
     $result = $optional->map($closure)->or('def');
     //then
     $this->assertEquals('def', $result);
 }
Beispiel #3
0
 /**
  * @test
  */
 public function shouldFilterIteratorElements()
 {
     //given
     $iterator = new \ArrayIterator(array('a', 'pref_a', 'pref_b', 'b'));
     //when
     $result = FluentIterator::from($iterator)->filter(FluentFunctions::startsWith('pref'))->reindex();
     //then
     $this->assertEquals(array('pref_a', 'pref_b'), $result->toArray());
 }