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

Dave Abrahams dabrahams at apple.com
Wed Apr 6 13:30:10 CDT 2016


on Wed Apr 06 2016, Milos Rankovic <milos-AT-milos-and-slavica.net> wrote:

>     On 6 Apr 2016, at 18:57, Xiaodi Wu via swift-evolution
>     <swift-evolution at swift.org> wrote:
>
>     Meanwhile, I was trying to talk about something like `stride(from: 200, to:
>     0, by: -2)`, which is easily expressed today but isn't straightforward at
>     all to preserve with only ranges.
>
> Precisely because the free function is also range-free, the sign of the step
> need not repeat the direction intent which is already indicated with `from: 200,
> to: 0`. In other words, I think this is much more intuitive:
>
> `stride(from: 200, to: 0, by: 2)`

But it leaves the “does it include 0?” question less clear than
something involving 0..<200 would.

-- 
Dave


More information about the swift-evolution mailing list