<div dir="ltr">Ah, yes. I apologize. The fact that state is inout, and the same instance is always passed in confused me. Thanks for the correction.</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 19, 2016 at 7:46 PM, Brent Royal-Gordon <span dir="ltr"><<a href="mailto:brent@architechies.com" target="_blank">brent@architechies.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">> Also note that there's a typo in the second example:<br>
><br>
> for view in sequence(initial: someView, next: { $0.<br>
> superview }) {<br>
><br>
> // someView, someView.superview, someView.superview.superview, ...<br>
><br>
> }<br>
><br>
><br>
> should be:<br>
><br>
> for view in sequence(state: someView, next: { $0.<br>
> superview }) {<br>
><br>
> // someView, someView.superview, someView.superview.superview, ...<br>
><br>
> }<br>
<br>
</span>I don't think these are mistakes—in each iteration of the loop, $0 is supposed to be the view from the previous iteration.<br>
<br>
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:<br>
<br>
let start = 1.0<br>
let end = 2.0<br>
let distance = 0.1<br>
<br>
for color in sequence(state: -1.0, next: { $0 += 1; let next = start + $0 * distance; return next < end ? next : nil }) {<br>
…<br>
}<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Brent Royal-Gordon<br>
Architechies<br>
<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Trent Nadeau</div>
</div>