[swift-evolution] Shorthand unwrap proposal

Charlie Monroe charlie at charliemonroe.net
Thu Jun 23 11:19:27 CDT 2016


Here is the thread:

http://thread.gmane.org/gmane.comp.lang.swift.evolution/17142

> On Jun 23, 2016, at 6:02 PM, James Campbell <james at supmenow.com> wrote:
> 
> Do we know what happened ? 
> 
> ___________________________________
> 
> 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 
> 
> 
> On 23 June 2016 at 16:42, Charlie Monroe <charlie at charliemonroe.net <mailto:charlie at charliemonroe.net>> wrote:
> There was a proposal not long ago floating around that there could be if and guard that would allow something like:
> 
> guard myReallyLongOptionalName! else {
> 	return
> }
> 
> /// Now myReallyLongOptionalName is guaranteed to be nonnull
> 
> -- OR --
> 
> if myReallyLongOptionalName! {
> 	doSomethingWith(myReallyLongOptionalName)
> }
> 
> 
> 
> 
>> On Jun 23, 2016, at 5:36 PM, James Campbell via swift-evolution <swift-evolution at swift.org <mailto: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)
>> }
>> 
>> 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 
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160623/c2d3e978/attachment.html>


More information about the swift-evolution mailing list