[swift-evolution] [swift-evolution-announce] [Review] SE-0094: Add sequence(initial:next:) and sequence(state:next:) to the stdlib
Brent Royal-Gordon
brent at architechies.com
Thu May 19 18:30:44 CDT 2016
> * What is your evaluation of the proposal?
This is an important and positive addition to the standard library. It allows us to quickly build ad-hoc sequences and, combined with `prefix(while:)`, easily simulates most of what the C-style `for` loop could do. I can easily imagine using this to convert complex `while let` loops like parent chain walking into `for` loops, create infinite sequences, prototype interesting generators, and do lots of other things that currently require much more work.
I especially like the way `sequence(state:next:)` is designed, with an `inout` state. The traditional functional design is quite awkward; this way is much better.
I could bikeshed the names a little—I'd prefer `sequence(first:next:)` and `sequence(state:each:)` to represent the slightly different roles the parameters have in the two calls—but ultimately this is a really solid design and I'm looking forward to seeing it in Swift.
> * Is the problem being addressed significant enough to warrant a change to Swift?
Yes. Enough pixels have been spilled over the C-style for loop alone. Let's put it to bed.
> * Does this proposal fit well with the feel and direction of Swift?
Yes. This is a super-flexible and elegant design, inspired by functional programming languages but much more usable in many ways.
> * If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
I've written a few loops that I would rewrite using `sequence(initial:next:)` now that it's available, but I've never actually used `unfold` or any equivalent to this function even in languages which supported them. They just seemed too abstract and disconnected from the problem I was trying to solve. `sequence(initial:next:)` avoids that problem by squarely addressing the common use case.
> * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
I've participated in discussions surrounding this feature from the beginning, including some private prototyping. (My prototype was `induce(from:while:by:)`; its naming turned out to be too clever by half, even in my own estimation, and the `while:` part turned out to be separable as `prefix(while:)`.)
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list