[swift-evolution] Remove forEach?
Chris Eidhof
chris at eidhof.nl
Tue Dec 8 21:02:59 CST 2015
That is a great example of the usefulness, Brent! I like it a lot =).
It seems like I’m the only one who actively dislikes it.
Just to give a little bit more background: I’ve taught some workshops on Swift, and this problem has come up more than once. Before sending my original email, I showed it to a friend in the office, he knew what the return inside forEach was doing, but said it was only because he’d been bitten by the exact same thing.
I liked Joe’s proposal. This might even get us a step closer to writing `while` and `for` in the standard library, rather than have them as built-in constructs…
Chris
> On 08 Dec 2015, at 17:47, Brent Royal-Gordon <brent at architechies.com> wrote:
>
>> As long as the `for` loop is in the language, I don’t really see the use of `forEach`.
>
> Here’s a typical use of forEach for me:
>
> generateABunchOfSubviews().forEach(addSubview)
>
> Seriously. I have one unreleased app which generates an entire software keyboard like that.
>
> You could write it like:
>
> for subview in generateABunchOfSubviews() {
> addSubview(subview)
> }
>
> But why use the extra lines and temporary variable when you don’t have to?
>
> --
> Brent Royal-Gordon
> Architechies
>
More information about the swift-evolution
mailing list