[swift-evolution] Feature proposal: Range operator with step

Stephen Canon scanon at apple.com
Wed Apr 6 13:06:30 CDT 2016

> On Apr 6, 2016, at 10:10 AM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
> on Wed Apr 06 2016, Brent Royal-Gordon <brent-AT-architechies.com> wrote:
>>> For example, there are all kinds of other ways to slice this:
>>>   stride(over: 0..<200, by: -2)
>> This seems like a particularly good solution. The way I understand it
>> at least, it would allow ranges to always be ordered, with the only
>> difference being whether it went start-to-end or end-to-start,
>> determined by the stride's sign.
> This is no different in principle from
>     (0..<200).striding(by: -2)
> Again, I wasn't trying to suggest any of the solutions listed there.
> The point I was making was that we don't have enough information to
> design more than
>    (0..<200).striding(by: -2)

Of the suggestions I’ve seen floated, this is my favorite by a huge margin.

- It preserves the ordering of range endpoints.
- It supports the right kind of half-open intervals—[a,b)—for zero-based indexing.
- It avoids making reverse iteration significantly more complex.

– Steve

More information about the swift-evolution mailing list