phpstreams\Stream::collect PHP Method

collect() public method

public collect ( phpstreams\Collector $collector )
$collector phpstreams\Collector
    public function collect(Collector $collector)
    {
        foreach ($this as $key => $value) {
            $collector->add($key, $value);
        }
        return $collector->get();
    }

Usage Example

Example #1
0
 /**
  * Test the collect method.
  */
 public function testCollect()
 {
     $instance = new Stream([1, 2, 3, 4]);
     $collector = $this->getMockBuilder('phpstreams\\Collector')->getMock();
     $collector->expects($this->exactly(4))->method('add');
     $collector->expects($this->once())->method('get')->willReturn(42);
     $this->assertEquals(42, $instance->collect($collector));
 }