diff --git a/src/Standard.php b/src/Standard.php index a2a3f03..75b83ea 100644 --- a/src/Standard.php +++ b/src/Standard.php @@ -374,12 +374,13 @@ public function count(): int return 0; } - if (!is_array($this->pipeline)) { - // Count values for an iterator. - $this->pipeline = iterator_to_array($this, false); + $result = 0; + + foreach ($this->pipeline as $value) { + ++$result; } - return count($this->pipeline); + return $result; } private static function makeNonRewindable(iterable $input): Generator