iter
iter copied to clipboard
Replace anonymous function by IteratorIterator
Hello,
Is there any reason to prefer the anonymous function than the IteratorIterator ?
I guess it's because you can only pass an object to IteratorIterator
, and not an array
.
"Argument 1 passed to IteratorIterator::__construct() must implement interface Traversable, array given"
The previous lines already check the fact that it is not an array
if (\is_array($iterable)) {
return new \ArrayIterator($iterable);
}
if ($iterable instanceof \Iterator) {
return $iterable;
}
if ($iterable instanceof \IteratorAggregate) {
return $iterable->getIterator();
}
Fair enough, didn't see that part when I wrote the comment. Ignore my feedback then :-)