public function testItApplyTheCallableOnEachItem() { $transducer = Fp\filtering(is_even_makker()); $squared = Fp\transduce($transducer, Fp\appending(), range(1, 6)); $this->assertEquals([2, 4, 6], $squared); }
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); }
public function testFilterWithCollection() { $this->assertEquals([2, 4], Fp\filter(is_even_makker(), new Fp\Collection\Collection([1, 2, 3, 4]))->values()); }
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); }