[swift-evolution] map-like operation that returns a dictionary
Kenny Leung
kenny_leung at pobox.com
Wed Jan 13 10:13:04 CST 2016
This solution looks great! How do you feel about “mapDict”?
-Kenny
> On Jan 12, 2016, at 10:28 AM, Craig Cruden <ccruden at novafore.com> wrote:
>
>>
>>
>> I named the method(s) „toDict“ instead of „map“ because map normally returns a collection which is either the same as the receiver or a simple one.
>> The second version is more general and allows to do things like
>>
>> let dict = ["Tom", "Dick", "Harry"].enumerate().toDict { (index, value) in (index + 1, value) }
>>
>
> Map would probably be a more correct mathematically speaking — but it would be inconsistent with the naming convention already chosen for Swift. So for Swift - toDict (or toDictionary) would be the best choice.
>
>
>
More information about the swift-evolution
mailing list