<div style="white-space:pre-wrap">I'm confused. There is an instance owning the start and end. It's called StrideTo or StrideThrough, conforms to Sequence (with a FIXME comment that it should conform to Collection) and is distinct from Range and from the Strideable bounds themselves. Is that different from what you're describing?<br><br>If I'm not misunderstanding, you're asking for a protocol common to StrideTo and StrideThrough to which other types such as a hypothetical NSDateStride could conform?<br></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Apr 7, 2016 at 5:25 PM Brent Royal-Gordon via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">>> Actually, it would need to be something like<br>
>> `calendar[startDate..<endDate, unit: .Day].striding(by: 1)`, because<br>
>> NSCalendarUnit is not itself a stride, it is the *unit* of the<br>
>> stride.<br>
><br>
> Maybe:<br>
><br>
> calendar.days[startDate..<endDate].striding(by: 1)<br>
<br>
I've been leaning towards parameters for additional flexibility, but the difference there is only slightly more than bikeshedding.<br>
<br>
> However, it doesn't explain why<br>
><br>
> calendar[startDate..<endDate, unit: .Day].striding(by: 1)<br>
><br>
> “doesn't quite help.” It seems to me that<br>
><br>
> calendar[startDate..<endDate, unit: .Day]<br>
><br>
> does factor in the calendar and unit.<br>
<br>
Yes, it does—as long as Strideable changes so that the instance created by this expression participates in the striding. My point is that, as long as the operations in Strideable are performed on one of the two strides, the "range" we're moving over can't be involved enough to help. Striding has to be done with the assistance of the instance owning the start and end, not just the start and end themselves.<br>
<br>
Basically, what I'm saying is that Strideable needs a redesign along the lines of the indexing system. We redesigned indexing so that the collection manipulates the indexes, rather than the indexes manipulating themselves, because the indexes don't always have enough information to do the job. We need to do the same thing with Strideable.<br>
<br>
>> For example, suppose you modify `Strideable` so that, instead of<br>
>> applying to the values participating in the striding, it applies to<br>
>> the instance containing those values:<br>
>><br>
>> public protocol Strideable {<br>
>> associatedtype Element: Comparable<br>
>> associatedtype Stride: SignedNumber<br>
>><br>
>> var start: Value<br>
>> var end: Value<br>
>><br>
>> public func distance(from earlier: Element, to later: Element) -> Stride<br>
>> public func advance(element: Element, by stride: Stride) -> Element<br>
>> }<br>
><br>
> Presumably you mean for Strideable to have a striding(by:_) method as well?<br>
<br>
Yes, there would be an extension method like that (or there would be a `func stride<StrideableType: Strideable>(over: StrideableType, by: StrideableType.Stride) -> …`, which is the same thing). I didn't include it because it's not a requirement imposed on the conforming type.<br>
<br>
> If so, how is this fundamentally different from Collection? Shouldn't<br>
> every Collection support this?<br>
<br>
Huh, interesting. Very, very interesting.<br>
<br>
Strideable is more widely applicable than Collection; for instance, a Range<Double> can't be a Collection (except via `nextafter`), but it is Strideable. But every RandomAccessCollection can be Strideable. (So could any BidirectionalCollection, for that matter, although it would be slower.) `array.striding(by: 2)` is a coherent and useful operation.<br>
<br>
So yes, I think every Collection (with a suitable index) could be Strideable. But there are Strideable things which aren't collections.<br>
<br>
> Except we don't have that capability today. Instead we'd be using<br>
> overloads of ..< and ... to produce more-capable range types, c.f.<br>
> <a href="https://github.com/apple/swift/blob/swift-3-indexing-model/stdlib/public/core/Range.swift#L504" rel="noreferrer" target="_blank">https://github.com/apple/swift/blob/swift-3-indexing-model/stdlib/public/core/Range.swift#L504</a><br>
> <a href="https://github.com/apple/swift/blob/swift-3-indexing-model/stdlib/public/core/Range.swift#L519" rel="noreferrer" target="_blank">https://github.com/apple/swift/blob/swift-3-indexing-model/stdlib/public/core/Range.swift#L519</a><br>
<br>
That works too, I suppose. You would end up with a StrideableRange "between" your current CountableRange (which is a Collection) and Range (which is a glorified tuple).<br>
<br>
--<br>
Brent Royal-Gordon<br>
Architechies<br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>