Exemplo n.º 1
0
 public function testFunctionWithDefault()
 {
     $array = [1, 2, 3, -4, 5, 6];
     $stream = new Stream($array);
     $stream->filter(new EvenFunction());
     $res = $stream->reduceWithDefault(new MinFunction(), -25);
     $this->assertFalse($res->isEmpty());
     $this->assertEquals(-4, $res->get());
 }
Exemplo n.º 2
0
 public function testMapCollector()
 {
     $array = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6];
     $stream = new Stream($array);
     $stream->filter(function ($value) {
         return intval($value) % 2 == 0;
     });
     $res = $stream->collect(new MapCollector());
     $this->assertEquals(['b' => 2, 'd' => 4, 'f' => 6], $res);
 }