[swift-evolution] [Pitch] Remove destructive consumption from Sequence
Dave Abrahams
dabrahams at apple.com
Thu Jun 30 17:39:12 CDT 2016
on Thu Jun 30 2016, Haravikk <swift-evolution-AT-haravikk.me> wrote:
>> On 30 Jun 2016, at 18:26, Dave Abrahams <dabrahams at apple.com> wrote:
>>
>> Q: Why should there be indices on an infinite multipass sequence?
>> A: Because the operations on indices apply equally well whether the
>> sequence is finite or not. Find the index of a value in the
>> sequence, slice the sequence, find again, etc.
>
> Would it not make more sense for sequences that can benefit from
> subscripts to just conform to Indexable?
All multi-pass sequences can benefit from subscripts.
> It seems like having basically all of the Collection-specific methods
> on Sequence too would be confusing, and dilute any nothing that these
> are sequences where elements are supposed to be consumed in-order, as
> it would give the illusion that you can skip around with the
> convenience of an array.
If traversal consumes the sequence, it is a single-pass thing.
> There's also the issue of how you would even index something that's
> potentially infinite; you'd need to use a big integer in which case
> you could end up with your indices growing to infinite size over time?
It's trivial; the index contains the iteration state. The only
fundamental difference between the constraints on Iterator and the
constraints on an Index is that Iterator doesn't support comparison for
equality.
--
Dave
More information about the swift-evolution
mailing list