[swift-evolution] Revisiting SE-0110
Joe Groff
jgroff at apple.com
Thu May 25 09:42:25 CDT 2017
> On May 24, 2017, at 6:18 PM, Ben Cohen via swift-evolution <swift-evolution at swift.org> wrote:
>
> I very much agree with your concerns about this change in general.
>
> On this specific example, though, I just wanted to point out that there doesn’t seem to be a good reason to use .forEach here.
>
> for (key, value) in self {
> // etc
> }
>
> Would work perfectly well and is clearer IMO, still works with destructing, doesn’t have gotcha problems related to continue/break not doing what you might expect, etc.
>
> forEach is only really a win when used on the end of a chain of map/filter-like operations, where for…in would involve bouncing back from right to left.
Furthermore, this probably comes up most commonly with dictionaries, since they're a sequence of tuples. The element tuple for dictionaries has element labels (key: Key, value: Value), so instead of writing `{ tuple in let (key, value) = tuple; f(key, value) }`, you could use the implicit argument and write `{ f($0.key, $0.value) }`.
-Joe
More information about the swift-evolution
mailing list