public function testMappingAndFirst()
 {
     $transformed = Fp\transduce(Fp\compose(Fp\mapping(square_makker()), Fp\first(function ($x) {
         return $x > 6;
     })), Fp\single_result(), range(1, 6));
     $this->assertEquals(9, $transformed);
 }
Exemplo n.º 2
0
 public function testItApplyTheCallableOnEachItem()
 {
     $transducer = Fp\mapping(square_makker());
     $squared = Fp\transduce($transducer, Fp\appending(), range(1, 2));
     $this->assertEquals([1, 4], $squared);
 }
Exemplo n.º 3
0
 public function testComposabilityWithHimself()
 {
     $composed = Fp\compose(plus_one_makker(), plus_one_makker(), Fp\compose(plus_one_makker(), square_makker()));
     $this->assertEquals(12, $composed(3));
 }
Exemplo n.º 4
0
 public function testMapWithCollection()
 {
     $this->assertEquals([1, 4, 9], Fp\map(square_makker(), new Fp\Collection\Collection([1, 2, 3]))->values());
 }
Exemplo n.º 5
0
 public function testTransducing()
 {
     $transduced = $this->collection->transduce(Fp\compose(Fp\map(square_makker()), Fp\filter(is_even_makker())), Fp\appending())->values();
     $this->assertEquals([4, 16], $transduced);
 }