[swift-evolution] [Pitch] Brace omission for single-statement n-ary closures
Charlie Monroe
charlie at charliemonroe.net
Thu May 26 00:43:41 CDT 2016
> 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)) }
I believe that in Scala (which has this feature), the entire content of the parenthesis is the statement and you need to use the placeholder (_ in Scala, $0 in Swift) to indicate it's a closure and not something else.
I've never been a fan of this as I don't think it improves readability, mostly when you start nesting stuff like:
array.map($0.tranform($0.uppercaseString))
which seems incredibly confusing.
> 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
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
More information about the swift-evolution
mailing list