on Thu Jun 30 2016, Haravikk <swift-evolution-AT-haravikk.me> wrote:

>> On 30 Jun 2016, at 18:26, Dave Abrahams <dabrah...@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
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to