How to annotate stateless iterators?
For stateful iterators, this is enough:
my_iter: (SomeType) -> (() -> SomeOtherType?)
How to annotate stateless iterators?
For stateful iterators, this is enough:
my_iter: (SomeType) -> (() -> SomeOtherType?)
Okay, I think this should work, but I’m not certain:
my_iter: (SomeType) -> ((IterState, IndexType?) -> SomeOtherType?, IterStateType, IndexType?)
Quite verbose…
I think this is right so long as SomeOtherType
is what your iterator yields on each iteration. I’m not sure what role SomeType
plays here though.
Object that is iterated over. It seems like annotations for stateful iterators also work as proper annotations to stateless ones, even though they aren’t exact.
Oh so SomeType
is the type of self, that makes sense, but yes they need to be interchangeable to be properly iterated, statefulness or not is really just an implementation detail, the for
will always hold state for you and continue advancing you regardless.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.