itertools icon indicating copy to clipboard operation
itertools copied to clipboard

`tee` behavior on unfused iterators

Open maugier opened this issue 4 years ago • 0 comments

The documentation for .tee() says:

Split into an iterator pair that both yield all elements from the original iterator.

It's not obvious from the documentation, but with the current implementation, the two iterators of the pair can yield different sequences if the underlying iterator is not fused.

I'll gladly submit a PR, but I'm not sure what the best route would be:

  • Make a note of this behavior in the documentation
  • Always fuse the underlying iterator
  • Require a FusedIterator and have the user explicitely fuse it when needed
  • Change the implementation to preserve the intermittent Nones produced by the underlying iterator

maugier avatar Dec 03 '21 12:12 maugier