<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Dmitri pointed out a few posts ago that Swift already has this.<div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> opInt: </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures;" class="">? = </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">nil</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">opInt</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(61, 29, 129);" class="">map</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""> {$0.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(61, 29, 129);" class="">toIntMax</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">()} </span><span style="font-variant-ligatures: no-common-ligatures;" class="">//Evaluates to nil</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">Are you talking about something different?</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">- Dave Sweeris</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><blockquote type="cite" class="">On Jun 23, 2016, at 2:04 PM, Charlie Monroe via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class="">Sure, the exact syntax is a matter of discussion, I just wasn't that much of favor of the very short<br class=""><br class="">doSomething(with: myOptional?)<br class=""><br class="">- it looks like a great idea, making the code really short<br class="">- on the other hand the question mark is next to the variable, but the method's execution is optional - in that sense something like doSomething(?: myOptional)(with: myOptional) makes more sense, declaring explicitely what optionals does the execution depend on.<br class="">- nevertheless, in the interest of clarity and readability of the code, I'm still in favor of the original proposal, which requires you to either use if or guard.<br class=""><br class=""><blockquote type="cite" class="">On Jun 23, 2016, at 8:57 PM, Tim Vermeulen <<a href="mailto:tvermeulen@me.com" class="">tvermeulen@me.com</a>> wrote:<br class=""><br class="">But ! still suggests force unwrapping, while ? suggests safe unwrapping. Why not use a question mark?<br class=""><br class=""><blockquote type="cite" class="">It was in the previous proposal and suggested that you are not trying to shadow the previous variable, but trying to unwrap it - and it acts as unwrapped from there on.<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Jun 23, 2016, at 8:52 PM, Tim Vermeulen<<a href="mailto:tvermeulen@me.com" class="">tvermeulen@me.com</a>>wrote:<br class=""><br class="">Why with the exclamation mark? It suggests you’re force unwrapping something.<br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">On Jun 23, 2016, at 8:45 PM, Tim Vermeulen via swift-evolution<<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>wrote:<br class=""><br class="">I would love to be able to do something like<br class=""><br class="">doSomething(with: myOptional?)<br class=""></blockquote>This actually looks good to me, though if I were a newcomer to the language, it would be really cryptic.<br class=""><br class="">In case the function returned any value, it could become an optional, just like with try?...<br class=""><br class="">I still, however, prefer the original proposal of if let myOptional! { doSomething(myOptional) }...<br class=""><br class=""><blockquote type="cite" class=""><br class="">which would be equivalent to<br class=""><br class="">if let myValue = myOptional {<br class="">doSomething(with: myValue)<br class="">}<br class=""><br class="">But it’s been discussed here before, and I don’t think people were very enthusiastic about it.<br class=""><br class=""><blockquote type="cite" class="">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.<br class=""><br class="">So this:<br class=""><br class="">let myReallyLongOptionalName: String? = "Hey"<br class=""><br class="">if let string = myReallyLongOptionalName {<br class="">doSomethingWith(string)<br class="">}<br class=""><br class="">Could become"<br class=""><br class="">let myReallyLongOptionalName: String? = "Hey"<br class=""><br class="">myReallyLongOptionalName.unwrap {<br class="">doSomethingWith($0)<br class="">}<br class=""><br class="">The block would only be fired if myReallyLongOptionalName has a value.<br class=""><br class=""><br class="">___________________________________<br class=""><br class=""><br class="">James⎥Head of Trolls<br class=""><br class=""><br class=""><a href="mailto:james@supmenow.com" class="">james@supmenow.com</a>(<a href="mailto:james@supmenow.com" class="">mailto:james@supmenow.com</a>)⎥<a href="http://supmenow.com" class="">supmenow.com</a>(<a href="http://supmenow.com" class="">http://supmenow.com</a>)<br class=""><br class=""><br class="">Sup<br class=""><br class=""><br class="">Runway East<br class=""><br class=""><br class="">10 Finsbury Square<br class=""><br class=""><br class="">London<br class=""><br class=""><br class="">EC2A 1AF<br class=""></blockquote>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote></blockquote></blockquote><br class=""><br class=""></blockquote></blockquote><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote><br class=""></body></html>