[swift-evolution] Shorthand unwrap proposal

James Campbell james at supmenow.com
Thu Jun 23 11:01:38 CDT 2016


Map requires you to return a value you wish to map the optional to, this is
more like a forEach that only fires when the Optional is .Some

*___________________________________*

*James⎥Head of Trolls*

*james at supmenow.com <james at supmenow.com>⎥supmenow.com <http://supmenow.com>*

*Sup*

*Runway East *

*10 Finsbury Square*

*London*

* EC2A 1AF *

On 23 June 2016 at 16:56, Dmitri Gribenko <gribozavr at gmail.com> wrote:

> 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>*/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160623/50f9516b/attachment.html>


More information about the swift-evolution mailing list