I’m a bit tore on this myself. I see the appeal, but let’s say we had such a 
function. If you wanted to use it with an named parameter it’d look like this:

myReallyLongOptionalName.unwrap { string in
  doSomethingWith(string)
}

And that is actually *more* characters than the current approach:

if let string = myReallyLongOptionalName {
  doSomethingWith(string)
}

However it’d be a big win especially when you can skip $0 and the braces 
entirely such as:

myReallyLongOptionalName.unwrap(doSomethingWith)

Of course if we were dealing with methods, you could write this like:

myReallyLongOptionalName?.doSomething()

And that is probably hard to beat.

So I think the problem really only presents itself when you have an optional 
that you need to unwrap and use as a parameter to something that does not take 
an optional.

I don’t have a solution - just trying to clarify the situation. :)

l8r
Sean


> On Jun 23, 2016, at 10:36 AM, James Campbell via swift-evolution 
> <[email protected]> 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)
> }
> 
> The block would only be fired if myReallyLongOptionalName has a value.
> 
> ___________________________________
> 
> James⎥Head of Trolls
> 
> [email protected]⎥supmenow.com
> 
> Sup
> 
> Runway East
> 
> 
> 10 Finsbury Square
> 
> London
> 
> 
> EC2A 1AF 
> 
> _______________________________________________
> 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

Reply via email to