Collection types currently have to provide two different implementations for iterating the items if you wont both a yielding method and an iterator: each(& : T ->)
and each : Iterator(T)
are completely separate. And the latter is usually more complex because it needs an extra iterator type to keep track of state.
If we had a reliable way to base an Iterator(T)
on a method that yields T
, it would be a huge improvement.
Currently, most standard collection types have both implementations. But many (especially outside of stdlib) don’t implement the iterator because it’s more work.
1 Like