phpstreams\Stream::count PHP Method

count() public method

This method may consume the stream, if it is not repeatable. Use it only when appropriate. As this is simply an implementation of the Countable interface, the count function may be used instead. However, this still may consume the stream.
public count ( ) : integer
return integer The number of elements in this Stream.
    public function count()
    {
        return iterator_count($this);
    }

Usage Example

Example #1
0
 public function testCount()
 {
     $stream = new Stream([1, 2, 3, 4, 5, 6]);
     $this->assertEquals(6, $stream->count());
     $this->assertEquals(6, count($stream));
     $filteredStream = $stream->filter(function ($value) {
         return $value % 2 == 1;
     });
     $this->assertEquals(3, $filteredStream->count());
 }