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); }
public function testItApplyTheCallableOnEachItem() { $transducer = Fp\mapping(square_makker()); $squared = Fp\transduce($transducer, Fp\appending(), range(1, 2)); $this->assertEquals([1, 4], $squared); }
public function testComposabilityWithHimself() { $composed = Fp\compose(plus_one_makker(), plus_one_makker(), Fp\compose(plus_one_makker(), square_makker())); $this->assertEquals(12, $composed(3)); }
public function testMapWithCollection() { $this->assertEquals([1, 4, 9], Fp\map(square_makker(), new Fp\Collection\Collection([1, 2, 3]))->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); }