[swift-evolution] Brainstorming: Optional sugar inferred map

Craig Cruden ccruden at novafore.com
Wed Jan 27 23:19:33 CST 2016


Swift currently encourages a lot of conditional code - especially when it comes to optionals.  In most cases when you are computing etc. on an Optional you would expect that you would want an optional result and things to be able to use optionals.  

In another language I generally just `map` one optional to another - which may not be the most readable code to some not use to optionals.  

I was wondering if maybe an expression is not available that it would rewrite the syntax to map from one to another value.  

So things like:

let n : Int? = 5

let r = n + 5

would actually compile as 

let r = n.map {$0 + 5}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160128/6d9ade47/attachment.html>


More information about the swift-evolution mailing list