[swift-evolution] [Pitch] Brace omission for single-statement n-ary closures
Brent Royal-Gordon
brent at architechies.com
Wed May 25 19:51:36 CDT 2016
> For single-statement closures, ordered parameters could be referenced in an autoclosure-like way using a placeholder for the parameter:
>
> let neg = [1, -2, 3].map(-abs(_))
I'm a big fan of this, or something like this, but the core team has rejected proposals like this before. They apparently believe that it would be difficult to tell how much of the expression you intended to make a closure of:
let neg = [1, -2, 3].map(-{ abs($0) })
let neg = [1, -2, 3].map({ -abs($0) })
let neg = { [1, -2, 3].map(-abs($0)) }
And believe that this syntax is limited in important ways, like being unable to reorder parameters. They think that closures with $N are more explicit and flexible while only requiring a little bit more code.
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list