[swift-evolution] [Pitch] Remove destructive consumption from Sequence
Jonathan Hull
jhull at gbis.com
Sun Jun 26 22:56:29 CDT 2016
Can’t a Sequence be potentially infinite, whereas a collection has a defined count/endIndex? Other than that, I agree with your statement.
Here is what I see as the appropriate structure:
Iterator: Single destructive pass, potentially infinite, (should be for-in able)
Sequence: Guaranteed non-destructive multi-pass (vends Iterators), potentially infinite, (should be subscript-able, gain most of collection, but lose anything that relies on it ending)
Collection: Multi-pass, guaranteed finite, (no changes from current form, except extra inits from Iterator/Sequence with end conditions)
Right now we are allowed to have an infinite sequence, but calling dropLast or non-lazy map will cause an infinite loop. These cases could be made much safer by considering the potentially infinite and finite cases separately...
Thanks,
Jon
> on Wed Jun 22 2016, David Waite <david-AT-alkaline-solutions.com> wrote:
>
> >> On Jun 22, 2016, at 2:57 PM, Dave Abrahams via swift-evolution <swift-evolution at swift.org <https://lists.swift.org/mailman/listinfo/swift-evolution>> wrote:
> >>
> >> <Ahem> “Iterators,” please.
> >
> > That makes me happy - for some reason I thought it was still GeneratorProtocol
> >
> >>> destructively, but such Generators would not conform to the needs of
> >>> Sequence. As such, the most significant impact would be the inability
> >>> to use such Generators in a for..in loop,
> >>
> >> Trying to evaluate this statement, it's clear we're missing lots of
> >> detail here:
> >>
> >> * Would you remove Sequence?
> >> * If so, what Protocol would embody “for...in-able?”
> > No, I would just remove the allowance in the documentation and API
> > design for a destructive/consuming iteration. Sequence would be the
> > interface to getting access to repeatable iteration, without the need
> > for meeting the other requirements for Collection.
>
> That would be wrong unless there exist substantial examples of a
> multipass Sequence that *can't* meet the other requirements of
> Collection without loss of efficiency. And since I can write an adaptor
> that turns any multipass sequence into a Collection, I think it's
> trivial to prove that no such examples exist.
>
> --
> -Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160626/9e5972e4/attachment-0001.html>
More information about the swift-evolution
mailing list