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

Brent Royal-Gordon brent at architechies.com
Thu Apr 14 20:27:01 CDT 2016

> for i in p1..<p2 by x
> as syntactic sugar for and internally mapped to
> for i in (p1..<p2).striding(by: x)
> Best of both worlds?

Look. It is very, very unlikely that you will get people to add syntactic sugar *just* for striding and *just* for the for loop. If this:

	for i in (1..<10).striding(by: 2) { … }

Is so ugly that we need special syntactic sugar for it, then so is this:

	(1..<10).striding(by: 2).map { … }

That means we would need an expression along the lines of:

	1..<10 by 2

Which could be used anywhere. Unfortunately, Swift does not allow word characters in identifiers, so `by` as an operator is a non-starter. I can't think of a non-letter operator for `by` that would make sense, so we're probably not going to go that route, either (but if you have a suggestion—preferably one backed by existing notation from, say, math—by all means suggest it).

I don't think you're going to make anything happen here.

Brent Royal-Gordon

More information about the swift-evolution mailing list