<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I would think the extra delimiters would just make it hairy — so if it were delimiter or not being able to be done I would think you would assign an intermediary value to another let. &nbsp;<div class=""><br class=""></div><div class="">i.e.&nbsp;</div><div class=""><br class=""></div><div class="">let n = pf? + 5</div><div class="">let hf =&nbsp;<span style="color: rgb(49, 89, 93); font-family: Menlo;" class="">doSomething(n?)</span></div><div class=""><font color="#31595d" face="Menlo" class=""><br class=""></font></div><div class=""><font color="#31595d" face="Menlo" class="">—</font></div><div class=""><font color="#31595d" face="Menlo" class=""><br class=""></font></div><div class=""><font color="#31595d" face="Menlo" class="">That being said I don’t see why their could not be a rule for inferred unwrapping. &nbsp;So if a function parameter was defined as Int and it was passed Some(Int) it would execute, but if it were None/Nil then it would skip execution. &nbsp;</font></div><div class=""><font color="#31595d" face="Menlo" class=""><br class=""></font></div><div class=""><font color="#31595d" face="Menlo" class=""><br class=""></font><div><blockquote type="cite" class=""><div class="">On 2016-01-31, at 12:24:03, Paul Ossenbruggen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">This is what I came up with so far. As Joe points out, it needs delimiters for more complex maps. Assume this for the examples:<div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">func</span>&nbsp;doSomething(value:&nbsp;<span style="color: rgb(112, 61, 170);" class="">Int</span>) -&gt;&nbsp;<span style="color: rgb(112, 61, 170);" class="">Int</span>&nbsp;{</div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(187, 44, 162);" class="">return</span>&nbsp;value</div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">let</span>&nbsp;pf :&nbsp;<span style="color: rgb(112, 61, 170);" class="">Int</span>? =&nbsp;<span style="color: rgb(39, 42, 216);" class="">5</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="color: rgb(187, 44, 162);" class="">let</span>&nbsp;pg :&nbsp;<span style="color: rgb(112, 61, 170);" class="">Int</span>? =&nbsp;<font color="#272ad8" class="">nil</font></div><div class=""><font color="#272ad8" class=""><br class=""></font></div><div class=""><span style="font-family: Helvetica;" class="">for simple expressions you could do this which is a pretty big win:</span></div><div class=""><span style="font-family: Helvetica;" class=""><br class=""></span></div></div></div><div class=""><div style="font-family: Menlo; margin: 0px; line-height: normal; color: rgb(49, 89, 93);" class=""><span style="color: rgb(187, 44, 162);" class="">let</span><span style="" class="">&nbsp;gf = pf? + 5</span></div><div style="font-family: Menlo; margin: 0px; line-height: normal; color: rgb(49, 89, 93);" class=""><span style="" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class="">For cases where the expression should not call a function if a parameter is nil, I came up with this for syntactic sugar which has delimiters. Inside the brackets the variable name is unwrapped automatically and real name of the variable is used. rather than $0. It is a win over the if let approach:</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo;" class=""><span style="color: rgb(39, 42, 216);" class="">// if let approach</span></div><div style="font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">let</span>&nbsp;ff : Int? = nil</div></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">if let pf = pf {</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">&nbsp;ff = doSomething(pf)&nbsp;</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class="">} &nbsp;</font></div><div style="margin: 0px; line-height: normal; color: rgb(49, 89, 93);" class=""></div><div class=""><br class=""></div><div class=""><div class=""><div class=""><font color="#272ad8" face="Menlo" class="">// the delimited approach is:</font></div><div style="font-family: Menlo; margin: 0px; line-height: normal; color: rgb(49, 89, 93);" class=""><span style="color: rgb(187, 44, 162);" class="">let</span><span style="" class="">&nbsp;gf = pf?{&nbsp;</span>doSomething<span style="" class="">(</span><span style="color: rgb(79, 129, 135);" class="">pf</span><span style="" class="">) } &nbsp;</span><span style="color: rgb(39, 42, 216);" class="">// pf not nil doSomething is called</span></div><div style="font-family: Menlo; margin: 0px; line-height: normal; color: rgb(49, 89, 93);" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="color: rgb(187, 44, 162);" class="">let</span><span style="" class="">&nbsp;gg =&nbsp;pg?{&nbsp;</span>doSomething<span style="" class="">(</span><span style="color: rgb(79, 129, 135);" class="">pg</span><span style="" class="">) }&nbsp;</span><span style="" class="">&nbsp;</span><span style="color: rgb(39, 42, 216);" class="">// pg is nil doSomething is not called.</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Helvetica;" class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class="">gf -&gt; 5</div></div><div style="font-family: Helvetica;" class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class="">gg -&gt; nil</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><div style="font-family: Helvetica;" class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal; color: rgb(49, 89, 93);" class=""><div style="" class=""><span style="color: rgb(39, 42, 216);" class="">// which is the equivalent of the map approach:</span></div></div><div class=""><span style="color: rgb(187, 44, 162);" class="">let</span>&nbsp;ff =&nbsp;<span style="color: rgb(79, 129, 135);" class="">pf</span>.<span style="color: rgb(61, 29, 129);" class="">map</span>&nbsp;{&nbsp;<span style="color: rgb(49, 89, 93);" class="">doSomething</span>($0) }</div></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="color: rgb(187, 44, 162);" class="">let</span>&nbsp;fg =&nbsp;<span style="color: rgb(79, 129, 135);" class="">pg</span>.<span style="color: rgb(61, 29, 129);" class="">map</span>&nbsp;{&nbsp;<span style="color: rgb(49, 89, 93);" class="">doSomething</span>($0) }</div><div class=""><br class=""></div></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class="">ff -&gt; 5</div></div><div style="font-family: Helvetica;" class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class="">fg -&gt; nil</div></div></div></div></div></div></div><div class=""><div class=""><br class=""></div><div class="">Assuming that this syntax is not a big enough win over the map version, This means that in this situation, you need to use map.. If doSomething() took an optional though you could do this, because doSomething would always be called.</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><span style="color: rgb(187, 44, 162); font-family: Menlo;" class="">let</span><span style="font-family: Menlo;" class="">&nbsp;gf =&nbsp;</span><font color="#31595d" face="Menlo" class="">doSomething</font><span style="font-family: Menlo;" class="">(</span><span style="color: rgb(79, 129, 135); font-family: Menlo;" class="">pf?</span><font face="Menlo" class="">) &nbsp;// result is optional, could also omit&nbsp;“?"</font></div><div style="font-family: Menlo; margin: 0px; line-height: normal; color: rgb(49, 89, 93);" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="color: rgb(187, 44, 162);" class="">let</span><span style="" class="">&nbsp;hf =&nbsp;</span>doSomething<span style="" class="">(</span><span style="color: rgb(79, 129, 135);" class="">pf? + 5</span><span style="" class="">) // result is still an optional</span></div></div><div style="font-family: Menlo; margin: 0px; line-height: normal; color: rgb(49, 89, 93);" class=""></div></div><div class=""><br class=""></div><div class="">- Paul<br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 30, 2016, at 10:28 AM, Joe Groff &lt;<a href="mailto:jgroff@apple.com" class="">jgroff@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class=""><blockquote type="cite" class="">On Jan 27, 2016, at 11:34 PM, Jacob Bandes-Storch via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">I've wanted this sort of thing a lot. It would also work for other functions, such as<br class=""><br class=""> &nbsp;&nbsp;&nbsp;manager.doSomething(data: data, count: n?)<br class=""><br class="">which is equivalent to<br class=""><br class=""> &nbsp;&nbsp;&nbsp;n.map { manager.doSomething(data: data, count: $0) }<br class=""><br class="">It might be hard to see exactly which operator/function applications such a thing applies to, if used in the context of a complex expression.<br class=""></blockquote><br class="">Yes, this would be a major problem with this sort of feature. Without some explicit delimiter for the bounds of the map operation, you have either extremely subtle rules for defining the implicit bounds, or an exponential type-checking problem figuring it out from context. <br class=""><br class="">-Joe</div></div></blockquote></div><br class=""></div></div></div></div></div>_______________________________________________<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=""></div></blockquote></div><br class=""></div></body></html>