[swift-evolution] [Review] SE-0094: Add sequence(initial:next:) and sequence(state:next:) to the stdlib

Trent Nadeau tanadeau at gmail.com
Thu May 19 19:51:45 CDT 2016


It would certainly be clearer that the state is changing on each
"iteration", but I'm not sure it's worth such a long parameter label. Maybe
`sequence(state:update:)`?

On Thu, May 19, 2016 at 8:46 PM, Patrick Smith <pgwsmith at gmail.com> wrote:

> Would `sequence(mutatingState:next:)` perhaps be clearer?
>
>
> On 20 May 2016, at 10:37 AM, Trent Nadeau via swift-evolution <
> swift-evolution at swift.org> wrote:
>
> Ah, yes. I apologize. The fact that state is inout, and the same instance
> is always passed in confused me. Thanks for the correction.
>
> On Thu, May 19, 2016 at 7:46 PM, Brent Royal-Gordon <
> brent at architechies.com> wrote:
>
>> > 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
>>
>>
>
>
> --
> Trent Nadeau
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
>


-- 
Trent Nadeau
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160519/1c730f85/attachment.html>


More information about the swift-evolution mailing list