예제 #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);
 }
예제 #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);
 }
예제 #3
0
 public function testItApplyTheCallableOnEachItem()
 {
     $transducer = Fp\mapping(square_makker());
     $squared = Fp\transduce($transducer, Fp\appending(), range(1, 2));
     $this->assertEquals([1, 4], $squared);
 }
예제 #4
0
 public function testIsAReducer()
 {
     $transducer = Fp\first(equal_three_makker());
     $this->assertInstanceOf('Fp\\Reducer\\Reducer', $transducer(Fp\appending()));
 }
예제 #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);
 }
예제 #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);
 }
예제 #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);
 }