Exemplo 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);
 }
Exemplo n.º 2
0
 public function testItEnumerateItems()
 {
     $transducer = Fp\enumerating();
     $transformed = Fp\transduce($transducer, Fp\appending(), range(1, 3));
     $this->assertEquals([[0, 1], [1, 2], [2, 3]], $transformed);
 }
Exemplo n.º 3
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.º 4
0
 public function testIsAReducer()
 {
     $transducer = Fp\first(equal_three_makker());
     $this->assertInstanceOf('Fp\\Reducer\\Reducer', $transducer(Fp\appending()));
 }
Exemplo n.º 5
0
 public function testCompositionWithMapFilterWithArityOfOne()
 {
     $transduced = Fp\transduce(Fp\compose(Fp\map(square_makker()), Fp\filter(is_even_makker())), Fp\appending(), [1, 2, 3, 4, 5, 6]);
     $this->assertEquals([4, 16, 36], $transduced);
 }
Exemplo n.º 6
0
 public function testPartialFinalBatch()
 {
     $transducer = Fp\batching(3);
     $transformed = Fp\transduce($transducer, Fp\appending(), range(1, 5));
     $this->assertEquals([[1, 2, 3], [4, 5]], $transformed);
 }
 public function testMappingAndBatching()
 {
     $transformed = Fp\transduce(Fp\compose(Fp\mapping(square_makker()), Fp\batching(3)), Fp\appending(), range(1, 6));
     $this->assertEquals([[1, 4, 9], [16, 25, 36]], $transformed);
 }
Exemplo n.º 8
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);
 }