[swift-evolution] [Discussion] stride behavior and a little bit of a call-back to digital numbers

Sune Foldager cyano at me.com
Sat Feb 27 16:46:04 CST 2016


> On 27 Feb 2016, at 01:12, Erica Sadun via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I have a problem with the way floating point ranges work with striding:
> 1.0.stride(through: 2.0, by: 0.1) returns the sequence [1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9].  
> Documentation: "It returns the sequence where last is less than or equal to `end`." 
> (And yes, the same issue exists with tradition C-style for loops).

The documentation is a bit weird. "It returns the sequence where last is less than or equal to `end`.” seems to tacitly assume that we’re talking about the longest possible sequence with that property. With your proposed "It returns the sequence where last is greater than or equal to `end`?” we’re now talking about the shortest possible sequence with that property.

But what do you mean “no change for integers”? What about 1.stride(through: 10, by: 8)? Wouldn’t that return [1, 9] now and [1, 9, 17] with your change?

—S

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160227/f5302311/attachment.html>


More information about the swift-evolution mailing list