[swift-evolution] What about renaming Optional.map to Optional.mapMe ?

Jay Zhao zhaojianyin at icloud.com
Mon Dec 5 23:03:41 CST 2016


What about mapUnwrapped ?

- Jay Zhao

> On 6 Dec 2016, at 12:48, David Sweeris <davesweeris at mac.com> wrote:
> 
> 
>> On Dec 5, 2016, at 7:46 PM, Jay Zhao via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> Hi there,
>> 
>> Code explains everything:
>> 
>> 	
>> 
>> /// Maybe a bad API naming in Swift? See below:
>> 
>>         /// array1 can be array of any object that have a `count` method
>>         let array1 = [[String]]()
>>         let array2 :[String]? = nil
>>         
>>         
>>         // I believe the confusion between `array.map` and `optionalArray.map` is really bad.
>>         // Because when you read code like this, you can not tell which is which:
>>         _ = array1.map({$0.count})
>>         _ = array2.map({$0.count})
>>         
>>         // It can be clearer:
>>         // 1, we pass `self.element` into the closure
>>         _ = array1.map({$0.count})
>>         // 2, we pass self directly into the closure
>>         _ = array2.mapMe({$0.count})
>> 
>> 
>> The mapFlat method is also problematic.
> 
> It might be possible to convince me to support renaming map for optionals, but not to mapMe. As it is, you’ll have the same problem with anything having a map function where the element(s) also have a map function. Sets of arrays, arrays of dictionaries, etc. 
> 
> - Dave Sweeris

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


More information about the swift-evolution mailing list