nikic / iter

Iteration primitives using generators
Other
1.12k stars 76 forks source link

Replace anonymous function by IteratorIterator #82

Open PCouaillier opened 4 years ago

PCouaillier commented 4 years ago

Hello,

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

drupol commented 4 years ago

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"

PCouaillier commented 4 years ago

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();
    }
drupol commented 4 years ago

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