<div style="white-space:pre-wrap">I&#39;m confused. There is an instance owning the start and end. It&#39;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&#39;re describing?<br><br>If I&#39;m not misunderstanding, you&#39;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 &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">&gt;&gt; Actually, it would need to be something like<br>
&gt;&gt; `calendar[startDate..&lt;endDate, unit: .Day].striding(by: 1)`, because<br>
&gt;&gt; NSCalendarUnit is not itself a stride, it is the *unit* of the<br>
&gt;&gt; stride.<br>
&gt;<br>
&gt; Maybe:<br>
&gt;<br>
&gt;  calendar.days[startDate..&lt;endDate].striding(by: 1)<br>
<br>
I&#39;ve been leaning towards parameters for additional flexibility, but the difference there is only slightly more than bikeshedding.<br>
<br>
&gt; However, it doesn&#39;t explain why<br>
&gt;<br>
&gt;  calendar[startDate..&lt;endDate, unit: .Day].striding(by: 1)<br>
&gt;<br>
&gt; “doesn&#39;t quite help.”  It seems to me that<br>
&gt;<br>
&gt;  calendar[startDate..&lt;endDate, unit: .Day]<br>
&gt;<br>
&gt; 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 &quot;range&quot; we&#39;re moving over can&#39;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&#39;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&#39;t always have enough information to do the job. We need to do the same thing with Strideable.<br>
<br>
&gt;&gt; For example, suppose you modify `Strideable` so that, instead of<br>
&gt;&gt; applying to the values participating in the striding, it applies to<br>
&gt;&gt; the instance containing those values:<br>
&gt;&gt;<br>
&gt;&gt;      public protocol Strideable {<br>
&gt;&gt;              associatedtype Element: Comparable<br>
&gt;&gt;              associatedtype Stride: SignedNumber<br>
&gt;&gt;<br>
&gt;&gt;              var start: Value<br>
&gt;&gt;              var end: Value<br>
&gt;&gt;<br>
&gt;&gt;              public func distance(from earlier: Element, to later: Element) -&gt; Stride<br>
&gt;&gt;              public func advance(element: Element, by stride: Stride) -&gt; Element<br>
&gt;&gt;      }<br>
&gt;<br>
&gt; 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&lt;StrideableType: Strideable&gt;(over: StrideableType, by: StrideableType.Stride) -&gt; …`, which is the same thing). I didn&#39;t include it because it&#39;s not a requirement imposed on the conforming type.<br>
<br>
&gt; If so, how is this fundamentally different from Collection?  Shouldn&#39;t<br>
&gt; every Collection support this?<br>
<br>
Huh, interesting. Very, very interesting.<br>
<br>
Strideable is more widely applicable than Collection; for instance, a Range&lt;Double&gt; can&#39;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&#39;t collections.<br>
<br>
&gt; Except we don&#39;t have that capability today.  Instead we&#39;d be using<br>
&gt; overloads of ..&lt; and ... to produce more-capable range types, c.f.<br>
&gt; <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>
&gt; <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 &quot;between&quot; 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>