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

Xiaodi Wu xiaodi.wu at gmail.com
Mon Dec 5 23:47:45 CST 2016


Here's a good explanation of map and some other functional idioms in Swift:
http://www.mokacoding.com/blog/functor-applicative-monads-in-pictures/

I hope it adequately explains to you why Optional, like Array, has a method
called map. Unwrapping and rewrapping is inherent to the meaning of the
term "map." Likewise, this article explains flatMap and what it does. These
are terms of art that have specific meanings. The idea of renaming them was
considered during Swift 3 evolution and the decision was made to keep them
as they are.

On Mon, Dec 5, 2016 at 23:35 Jay Zhao via swift-evolution <
swift-evolution at swift.org> wrote:

> We can make the code condense when the optional is used *as a parameter*:
>
> /// Long version
>         if let doubleValue = json["taken_at"].double {
>             self.createTime = Date(timeIntervalSince1970:doubleValue)
>         }
>
>
>         /// Shourt version
>         self.createTime = json["taken_at"].double.mapUnwrapped{ Date(timeIntervalSince1970:$0)
> }
>
>
>
> On 6 Dec 2016, at 13:18, David Sweeris <davesweeris at mac.com> wrote:
>
>
> On Dec 5, 2016, at 9:17 PM, David Sweeris via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>
> On Dec 5, 2016, at 8:54 PM, Jay Zhao <zhaojianyin at icloud.com> wrote:
>
> What about mapUnwrapped ?
>
>
> If the name is anything other than “map”, you already have to think of the
> “special” word. At that point, why not just unwrap it manually?
> _ = array2?.count
> vs
> _ = array2?.map {$0.count}
>
> Oops, there shouldn’t be a “?" on the last line
>
>
> _______________________________________________
> 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/f143894b/attachment.html>


More information about the swift-evolution mailing list