[swift-evolution] Shorthand unwrap proposal

Dmitri Gribenko gribozavr at gmail.com
Thu Jun 23 10:56:52 CDT 2016


On Thu, Jun 23, 2016 at 8:36 AM, James Campbell via swift-evolution
<swift-evolution at swift.org> wrote:
> I was wondering if people would be open to adding an unwrap method to the
> Optional type,  I already have a method like this which shortens code for
> me.
>
> So this:
>
> let myReallyLongOptionalName: String? = "Hey"
>
> if let string = myReallyLongOptionalName {
>   doSomethingWith(string)
> }
>
> Could become"
>
> let myReallyLongOptionalName: String? = "Hey"
>
> myReallyLongOptionalName.unwrap {
>   doSomethingWith($0)
> }

We have that, it is called '.map'.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-evolution mailing list