> Also note that there's a typo in the second example:
> 
> for view in sequence(initial: someView, next: { $0.
> superview }) {
>     
> // someView, someView.superview, someView.superview.superview, ...
> 
> }
> 
> 
> should be:
> 
> for view in sequence(state: someView, next: { $0.
> superview }) {
>     
> // someView, someView.superview, someView.superview.superview, ...
> 
> }

I don't think these are mistakes—in each iteration of the loop, $0 is supposed 
to be the view from the previous iteration.

If you wanted an example using `state`, here's one which is roughly equivalent 
to `stride(from: 1.0, to: 2.0, by: 0.1)`, using a non-error-accumulating 
algorithm:

        let start = 1.0
        let end = 2.0
        let distance = 0.1
        
        for color in sequence(state: -1.0, next: { $0 += 1; let next = start + 
$0 * distance; return next < end ? next : nil }) {
                …
        }

-- 
Brent Royal-Gordon
Architechies

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to