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 < [email protected]> 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 <[email protected]> wrote: > > > On Dec 5, 2016, at 9:17 PM, David Sweeris via swift-evolution < > [email protected]> wrote: > > > On Dec 5, 2016, at 8:54 PM, Jay Zhao <[email protected]> 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 > [email protected] > https://lists.swift.org/mailman/listinfo/swift-evolution >
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
