[swift-evolution] Spread Operator as Shorthand for Map
Matthew Johnson
matthew at anandabits.com
Mon Dec 28 12:33:51 CST 2015
> On Dec 28, 2015, at 11:10 AM, Thorsten Seitz via swift-evolution <swift-evolution at swift.org> wrote:
>
> +1 for being able to use cars.map(make)
Check out the thread "[Proposal Idea] dot shorthand for instance members” which discusses an idea that gets as close to that as possible.
Something like this is also mentioned in the "Alternatives considered” section of Joe Groff’s “Removing currying func declaration syntax” proposal: https://github.com/apple/swift-evolution/blob/master/proposals/0002-remove-currying.md <https://github.com/apple/swift-evolution/blob/master/proposals/0002-remove-currying.md>
>
> Am 16.12.2015 um 16:23 schrieb Al Skipp via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>>:
>
>>> On 16 Dec 2015, at 12:47, Sean Kosanovich via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>
>>> As a Groovy user, I really enjoy the shorthand Spread Operator over the Collect Closure (Map is the equivalent in Swift).
>>>
>>> Consider the following Swift code:
>>>
>>> struct Car {
>>> let make: String
>>> let model: String
>>> }
>>>
>>> let cars = [Car(make: "Jeep", model: "Grand Cherokee"), Car(make: "Dodge", model: "Challenger")]
>>> let makes = cars.map() { $0.make }
>>>
>>>
>>>
>>> Now consider the same code using a Spread Operator:
>>>
>>> let makes = cars*.make
>>
>> I think there is a tension in Swift between its object oriented nature and higher-order functions which leads to a lot of repetition of { $0.property }
>>
>> In this example:
>> cars.map { $0.make }
>>
>> I’d like to write the following, but ‘make’ is a member, not a free function:
>> cars.map(make)
>>
>> Is anyone else irked by the preponderance of { $0.property } in Swift (or is it just me being grumpy)? Not sure what the solution would be, but I can’t say I’m keen on the suggestion of:
>>
>> cars*.make
>>
>> It’s too mysterious.
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151228/68c210dc/attachment.html>
More information about the swift-evolution
mailing list