[swift-evolution] For-loop revisited

Erica Sadun erica at ericasadun.com
Tue Mar 8 12:15:36 CST 2016


> On Mar 8, 2016, at 11:13 AM, Maximilian Hünenberger via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Actually you cannot use the global stride function anymore.

https://github.com/apple/swift-evolution/blob/master/proposals/0006-apply-api-guidelines-to-the-standard-library.md <https://github.com/apple/swift-evolution/blob/master/proposals/0006-apply-api-guidelines-to-the-standard-library.md>

 extension Strideable {
-  public func stride(to end: Self, by stride: Stride) -> StrideTo<Self>
 }
+public func stride<T : Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T>

 extension Strideable {
-  public func stride(through end: Self, by stride: Stride) -> StrideThrough<Self>
 }
+public func stride<T : Strideable>(from start: T, through end: T, by stride: T.Stride) -> StrideThrough<T>


> I thought a method on "Range" which returns a stride would be easier to grasp:
> 
> for x in 0.stride(to: 0.5, by: 0.03) { ... }
> 
> // much faster to predict what is does even though it is less clear to a beginner
> for x in (0 ... 0.5).by(0.03) { ... }
> 
> - Maximilian
> 
>> Am 08.03.2016 um 18:56 schrieb Антон Жилин <antonyzhilin at gmail.com>:
>> 
>> It's already possible:
>> 
>> for d in stride(from: 0, to: 5, by: 0.3) {
>> }
>> 
>> Absolutely readable (despite all efforts to break it).
>> And I would passionately hate the special syntax for floating-point loops in Swift.
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

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


More information about the swift-evolution mailing list