[Python-ideas] Membership of infinite iterators
elazarg at gmail.com
Mon Oct 16 23:27:29 EDT 2017
בתאריך יום ג׳, 17 באוק׳ 2017, 00:13, מאת Terry Reedy <tjreedy at udel.edu>:
> On 10/15/2017 9:12 PM, Jason Campbell wrote:
> > itertools.cycle could use membership from the underlying iterable
> If the underlying iterable is an iterator, this does not work. You
> could define a Cycle class that requires that the input have .__contain__.
> > itertools.repeat is even easier, just compare to the repeatable element
> Again, create a Repeat(ob) class whose .__iter__ returns repeat(ob) and
> that has .__contains__(x) returning 'x == ob'.
> > Does anyone else think this would be useful?
> itertools is not going to switch from iterators to non-iterator iterables.
It doesn't have to switch, and does not have to _require_ the input to
define __contains__ method for the proposal to be meaningful. It can work
with the same kind of iterables as its inputs, delegating whenever
possible. I'm sure there are good reasons not to do it, but that's not an
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas