[swift-evolution] [Proposal] Conventionalizing stride semantics
erica at ericasadun.com
Tue Mar 1 11:23:08 CST 2016
> On Mar 1, 2016, at 2:00 AM, Haravikk <swift-evolution at haravikk.me> wrote:
> I still wonder if a better solution might involve the same syntax as ranges currently benefit from, i.e:
> 0 ..< 10 // [0, 10) with an increment of 1
> (0 … 10).stride(2) // [0, 10] with an increment of 2
> The most important change is that the default type for this should be able to handle higher starting indices, e.g:
> (10 … 0).stride(2) // [10, 0] with a decrement of 2
> Basically I don’t like the stride global function in the first place =)
> The benefit of the Range syntax is that it’s clear whether the end point is inclusive or exclusive, and it’s nice and succinct. The problem right now is just that ranges have a limit on the direction they can be traversed in for things like accessing slices of collections, in which case we’ll need to make sure that these still retain the same limitation.
This would have to be a separate proposal to allow descending ranges. I think that would be a good addition to the language and encourage you to write it.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution