[swift-evolution] Spread Operator as Shorthand for Map

Matthew Johnson matthew at anandabits.com
Wed Dec 16 11:20:02 CST 2015


>> 
>>     cars.map{.make}
> 
> This last alternative looks a lot like a special (single expression) case of the Method Cascading proposal <https://bugs.swift.org/browse/SR-160 <https://bugs.swift.org/browse/SR-160>>. If you want to go forward with this shorthand, I’d suggest adding it to method cascading as a rule: Invoking a closure with a single anonymous argument also implicitly begins a cascade with $0 as the default receiver.

Thanks for bringing this up!  It is not a special case of that specific proposal but it is a special case of a variation of the proposal that was discussed.  Seeing it applied in this context is really interesting.  

Joe Groff noted syntactic ambiguity caused by omitting $0.  Unless that potential ambiguity could be resolved in some way this wouldn’t actually work.  It does work if you include $0:

cars.map{$0.make}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151216/ccbf2cc8/attachment.html>


More information about the swift-evolution mailing list