iter icon indicating copy to clipboard operation
iter copied to clipboard

Replace anonymous function by IteratorIterator

Open PCouaillier opened this issue 5 years ago • 3 comments

Hello,

Is there any reason to prefer the anonymous function than the IteratorIterator ?

PCouaillier avatar Jan 07 '20 14:01 PCouaillier

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"

drupol avatar Sep 26 '20 14:09 drupol

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();
    }

PCouaillier avatar Sep 26 '20 16:09 PCouaillier

Fair enough, didn't see that part when I wrote the comment. Ignore my feedback then :-)

drupol avatar Sep 27 '20 16:09 drupol