[swift-evolution] Shorthand unwrap proposal
Tim Vermeulen
tvermeulen at me.com
Thu Jun 23 13:45:08 CDT 2016
I would love to be able to do something like
doSomething(with: myOptional?)
which would be equivalent to
if let myValue = myOptional {
doSomething(with: myValue)
}
But it’s been discussed here before, and I don’t think people were very enthusiastic about it.
> 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)
> }
>
> The block would only be fired if myReallyLongOptionalName has a value.
>
>
> ___________________________________
>
>
> James⎥Head of Trolls
>
>
> james at supmenow.com(mailto:james at supmenow.com)⎥supmenow.com(http://supmenow.com)
>
>
> Sup
>
>
> Runway East
>
>
> 10 Finsbury Square
>
>
> London
>
>
> EC2A 1AF
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
More information about the swift-evolution
mailing list