Closed shadowrylander closed 2 years ago
Hello @shadowrylander
Yeah, I think you are mixing Iterables and Iterators.
You can't get "the next item" from an Iterable, only from an Iterator.
Even from a simple range
you can't get a "next" item, look:
It's the same thing with my AliveIt adapter:
It's kinda tricky to implement both __iter__
and __next__
, and you probably don't need that!
Together they serve a different purpose, which is not this scope.
But you should implement this using only __iter__
, and make it a generator, where you yield
the elements you need.
You can even use yield from alive_it()
, and let Python work for you.
So would something like this in __iter__
work?
if isinstance(self.output, __AliveBarIteratorAdapter):
yield from self.output
else:
return self
Ahp; wait; never mind. Just turn the whole damn thing into a generator using yield from
. Thanks for this new fun concept to play with! 😹😹😹😹 And thank you kindly for all the help as well!
You're welcome 👍
Hello!
If a certain keyword is passed in, my module
bakery
returns an iterable (I think? Still confused with those) wrapped in youralive_it
function; however, if I were to usefor
on it, such asfor item in bakery(alive = True)
, I getTypeError: '__AliveBarIteratorAdapter' object is not an iterator
; this is the relevant code, translated fromhylang
:How would I go about fixing this?
Thank you kindly for the help!