On Sat, May 9, 2020 at 1:58 PM Alex Hall email@example.com wrote:
And the prototype implementation:
I think this is a good idea. For sequences I'm not sure how big the benefit is - I get that it's more efficient, but I rarely care that much, because most lists are small. Why not extend the proposal to all iterators, or at least common ones like generators? That would allow avoiding itertools when I have no other choice.
I'm still confused what you mean by extend to all iterators? you mean that you could use slice syntax with anything iterable>
And where does this fit in to the iterable vs iterator continuum?
iterables will return an iterator when iter() is called on them. So are you suggesting that another way to get an iterator from an iterable would be to pass a slice somehow that would return an iterator off that slice?
for i in an_iterable(a:b:c): ...
would work for any iterable? and use an iterator that would iterate as specified by the slice?
That is kind of cool.
Though it is heading in a different direction that where Andrew was proposing, that this would be about making and using views on sequences, which really wouldn't make sense for any iterator.
And, of course, adding syntax is a heavier lift (though extending a major built in protocol is not a small lift by any means)