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

Thorsten Seitz tseitz42 at icloud.com
Tue Apr 19 03:17:09 CDT 2016


-1

I don't see the need for special syntax where a method can be easily used and is more general.

-Thorsten 

> Am 18.04.2016 um 17:28 schrieb Vladimir.S via swift-evolution <swift-evolution at swift.org>:
> 
> On 15.04.2016 3:57, Hans Huck via swift-evolution wrote:
> > Anyway, why not just make it .step() then, like in Ruby?
> >
> > Instead of a "by" keyword, I'd be happy with syntactic sugar in the form of
> >
> > for i in p1..<p2 step x
> 
> As for 'step' word: It seems like for now IMO this is the best suggestion : very explicit, anyone knows what "step" means especially in context of loop, clear that "step" belongs to for-in construction(not to range itself).
> 
> for i in 0..<10 step 2 {
> }
> 
> for i in 0..<10 step -2 {
> }
> 
> for i in 0.1..<10.5 step 0.5 {
> }
> 
> all are mapped to needed ranges/intervals under the hood
> Do you want some custom Range-specific methods to provide steps for loop - no problems, use what you need. But don't force any of us to use (0..<10).striding(by:2) for myriads of simple loops in our code.
> 
> I want to see such constructions in our Swift. Who is with me ? :)
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution


More information about the swift-evolution mailing list