public function testMapCollector() { $array = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6]; $stream = new Stream($array); $stream->map(new SquareFunction()); $res = $stream->collect(new MapCollector()); $this->assertEquals(['a' => 1, 'b' => 4, 'c' => 9, 'd' => 16, 'e' => 25, 'f' => 36], $res); }
public function testSkipMapCollector() { $array = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6]; $stream = new Stream($array); $stream->skip(3); $res = $stream->collect(new MapCollector()); $this->assertEquals(['d' => 4, 'e' => 5, 'f' => 6], $res); }
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); }