Yikes. Not too concerned about the infinite loop issue, as floating point strides when fixed to avoid error accumulation will necessarily enforce a finite number of steps. However, you're talking a regular, not-at-all-lazy Array being returned? That would be not good at all...
On Sun, Apr 10, 2016 at 12:29 AM Dave via swift-evolution < swift-evolution@swift.org> wrote: > > On Apr 9, 2016, at 4:33 AM, Haravikk via swift-evolution < > swift-evolution@swift.org> wrote: > > While I’m in favour of the basic idea I think the operator selection is > too complex, and I’m not sure about the need for negative strides. Really > all I want are the following: > > (0 ... 6).striding(by: 2) // [0, 2, 4, 6] x from 0 to 6 > (0 ..< 6).striding(by: 2) // [0, 2, 4] x from 0 while <6 > (6 ... 0).striding(by: 2) // [6, 4, 2, 0] x from 6 to 0 > (6 ..> 0).striding(by: 2) // [6, 4, 2] x from 6 while >0 > > Everything else should be coverable either by flipping the order, or using > .reverse(). The main advantage is that there’s only one new operator to > clarify the 6 ..> 0 case, though you could always just reuse the existing > operator if you just interpret it as “x from 6 to, but not including, 0" > > > `.reverse()` returns an array, though, not a StrideTo<>, which means it’ll > get in an infinite loop on infinite sequences. This works fine: > for i in stride(from: 0.0, to: Double.infinity, by: M_PI) { > if someTestInvolving(i) { break } > ... > } > > But this never even starts executing the loop because of the infinite loop > inside `.reverse()`: > for i in stride(from: -Double.infinity, to: 0.0, by: M_PI).reverse() { > if someTestInvolving(i) { break } > ... > } > > - Dave Sweeris > _______________________________________________ > swift-evolution mailing list > swift-evolution@swift.org > https://lists.swift.org/mailman/listinfo/swift-evolution >
_______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution