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

Robert Widmann devteam.codafi at gmail.com
Tue Dec 6 18:05:47 CST 2016


If you think of Optional as a zero-or-one element collection there's really no reason this operation should be named any differently.  It still lifts a function over values to one over Optionals.  It still extracts the contents of the structure and applies the function (propagating failure if necessary).  The operation is no different from the one required of a plain Sequence conformance, why should it have a new name if it is not a new operation? 

~Robert Widmann

2016/12/05 22:46、Jay Zhao via swift-evolution <swift-evolution at swift.org> のメッセージ:

> 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.
> 
> Yours,
> Jay Zhao
> _______________________________________________
> 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/20161206/dbb3e3f0/attachment.html>


More information about the swift-evolution mailing list