[swift-evolution] map-like operation that returns a dictionary

Thorsten Seitz tseitz42 at icloud.com
Wed Jan 13 11:41:23 CST 2016


I'd prefer "mapToDict" otherwise it sounds like a dictionary gets mapped, at least for me.

-Thorsten

> Am 13.01.2016 um 17:13 schrieb Kenny Leung via swift-evolution <swift-evolution at swift.org>:
> 
> 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.
> 
> _______________________________________________
> 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