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

David Waite david at alkaline-solutions.com
Tue Dec 6 21:37:24 CST 2016


This might be a bit of a side question, but do you use optional arrays in your code? If so, what is the distinction between no array and an empty array?

I believe I haven’t had this confusion in practice because I assume “cars” is a collection, not an optional.

-DW

> On Dec 5, 2016, at 8:46 PM, Jay Zhao via swift-evolution <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.
> 
> 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/21ff16ae/attachment.html>


More information about the swift-evolution mailing list