Esempio n. 1
0
 public function testItApplyTheCallableOnEachItem()
 {
     $transducer = Fp\filtering(is_even_makker());
     $squared = Fp\transduce($transducer, Fp\appending(), range(1, 6));
     $this->assertEquals([2, 4, 6], $squared);
 }
Esempio n. 2
0
 public function testItReturnASingleValueForCollectionTransducer()
 {
     $transducer = Fp\filtering(is_even_makker());
     $reduced = Fp\transduce($transducer, Fp\single_result(), range(3, 6));
     $this->assertEquals(4, $reduced);
 }
 public function testMappingAndFilteringAndEnumeratingComposition()
 {
     $transformed = Fp\transduce(Fp\compose(Fp\mapping(square_makker()), Fp\filtering(is_even_makker()), Fp\enumerating()), Fp\appending(), range(1, 6));
     $this->assertEquals([[0, 4], [1, 16], [2, 36]], $transformed);
 }
Esempio n. 4
0
 public function testFilterWithCollection()
 {
     $this->assertEquals([2, 4], Fp\filter(is_even_makker(), new Fp\Collection\Collection([1, 2, 3, 4]))->values());
 }
Esempio 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);
 }