[swift-evolution] Spread Operator as Shorthand for Map

Greg Titus greg at omnigroup.com
Wed Dec 16 10:32:01 CST 2015


> On Dec 16, 2015, at 8:18 AM, Stephen Celis via swift-evolution <swift-evolution at swift.org> wrote:
> 
> On Wed, Dec 16, 2015 at 10:50 AM, Matthew Johnson via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
> If we peel off just the contextual shorthand aspect of this proposal you could write:
> 
> cars.map(.make)
> 
> That does seem like a big win if it is feasible (doesn’t introduce ambiguity or cause other significant challenges in implementation).
> 
> The above creates ambiguity if there were a `map` function that takes a type with a static member `make`.
> 
> Alternatively:
> 
>     cars.map{.make}
> 
> Both create an additional meaning for dot abbreviation, though, which is confusing. I think I'm "-1" on this proposal as is. The existing form is clearer and relatively short as is.

This last alternative looks a lot like a special (single expression) case of the Method Cascading proposal <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.

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


More information about the swift-evolution mailing list