Looks pretty good. I'll send you my gists tomorrow so we can compare.
The problem with calling next()
repeatedly on an iterator that has returned nil
is that back in swift 1 it was a programmer error to do so.
And then they realized that IIRC Zip2Iterator
was violating this, and changed to "if it has returned nil
it must return nil indefinitely"
Shouldnât do. A single lazy flatmap returns something massive like that, too.
If you erase the sequences, you lose the ability to make the result conditionally conform to things like RandomAccessCollection. Youâve basically remade âjoinedâ.
This is an excellent point that I hadn't considered.
Updated proposal here: (removed)
Feedback requestedIf belong on the author list, let me know (I'll need a github user url)
I have a strong feeling @Joe_Groff or @Douglas_Gregor will quickly say "Break it down into three proposals instead" , so I'm user-name pinging them. I also suspect they will say "Expand the motivation section".
Since thebatched
andappending
items are not originally sourced from my first proposal, please send me some great motivation and examples.
I apologize for any harm I have caused by creating the draft of a unified proposal.
Without having read the rest of this thread, calling next()
on an exhausted iterator (i.e. one that has returned nil
in the past) used to be unsafe (or rather, implementation-defined), but some time ago (Swift 2.0 maybe?) it was redefined as being explicitly safe. From the documentation on IteratorProtocol.next()
:
Repeatedly calling this method returns, in order, all the elements of the underlying sequence. As soon as the sequence has run out of elements, all subsequent calls return
nil
.
A few years ago it used to be the case that calling next() after exhaustion was undefined, but a year or so ago the documentation/requirement was changed so that next() could be called after exhaustion and it would continue returning nil.
I really would've wished you had asked me before putting my name on a proposal. I understand you were already working on cycling but I wasn't intending on trying to compete with your proposal. I'm not sure we were done discussing the other items. At any rate, I think you can take it from here, thanks.
It's just a gist, not a proposal. I'm happy to return it to the previous form and apologize for any discomfort I have caused.
No worries, please run with it.
Again, it's just a draft to move the discussion forward. Just let me know what you are and are not comfortable with and I'll update accordingly.
I think I'm going to take a step back from the discussion for the time being. If you're interested in seeing these APIs through, then please do add them to your proposal. You can leave my name off, if you would. Thanks!
Removed as you requested. Still happy to hear feedback and suggestions.
Normally when someone asks to be removed, there's something fundamentally flawed with the proposal. Is there anything in particular I can fix or parts that stand out as something you don't want to associate with?
I like where the proposal is headed. Thanks for asking!
I really like the idea of replication of itertools
for Swift. Unfortunately, the generality of itertools
will be pretty much impossible to achieve without variadic generics. This proposal is not worth it if everything needs to by type-erased.
Like itertools
, in Swift's version all operations should be as lazy as possible, consuming Sequence
s only when necessary. With regard to exhausting single-pass iterators, I believe that itertools
's behavior is to store a copy of the results as they are produced, and then to return the copies as needed (for repeat
, for instance).
For anyone tracking this topic, I am deliberately sitting on this proposal until @Dave_Abrahams1 has time for feedback on this forum thread: [Pitch] Make Collection Super-Convenient and Retire Sequence