<div dir="ltr">Hello, <div><br></div><div>Let&#39;s assume I have an optional &quot;name&quot; parameter, based on the optional status of the parameters I would like to compose string with either the unwrapped value of name, or the string &quot;null&quot;. The use case for is syntactic sugar to compose a GraphQL queries.<br></div><div><br></div><div>A (sampled) illustration of the code that currently solves it looks as following:</div><div><br></div><div><div><font face="monospace">func query(name: String?) {</font></div><div><font face="monospace">  <span style="color:rgb(5,0,0);font-size:9.75px;white-space:pre-wrap;background-color:rgb(255,254,254)">let variables_name = name != nil ? &quot;\&quot;\(name!)\&quot;&quot; : &quot;null&quot;</span></font></div><div><font face="monospace"><span style="white-space:pre-wrap;background-color:rgb(255,254,254)">  </span><span style="color:rgb(5,0,0);font-size:9.75px;white-space:pre-wrap;background-color:rgb(255,254,254)">return &quot;{ param: \(</span><span style="color:rgb(5,0,0);font-size:9.75px;white-space:pre-wrap;background-color:rgb(255,254,254)">variables_name</span><span style="color:rgb(5,0,0);font-size:9.75px;white-space:pre-wrap;background-color:rgb(255,254,254)">) }&quot;</span></font></div><div><span style="font-family:monospace;color:rgb(5,0,0);font-size:9.75px;white-space:pre-wrap;background-color:rgb(255,254,254)">}</span><br></div></div><div><br></div><div>Based on optional status the following output is expected</div><div><br></div><div><font face="monospace">let name = &quot;Max&quot;</font></div><div><font face="monospace">query(name: name) </font></div><div><font face="monospace">// { param: &quot;Max&quot; }</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">let name: String? = nil</font></div><div><font face="monospace">query(name: name)</font></div><div><font face="monospace">// { param: null }</font></div><div><br></div><div>I think it might be useful to have an conditional unwrap operator <font face="monospace">!?</font> that would enable syntax sugar uch as the following built into the language:</div><div><br></div><div><font face="monospace">func query(name: String?) {</font></div><div><font face="monospace">  <span style="color:rgb(5,0,0);font-size:9.75px;white-space:pre-wrap;background-color:rgb(255,254,254)">return &quot;{ param: \(name !? &quot;\&quot;\(name)\&quot;&quot;: &quot;null&quot;) }&quot;</span></font></div><div><font face="monospace"><span style="color:rgb(5,0,0);font-size:9.75px;white-space:pre-wrap;background-color:rgb(255,254,254)">}</span><br></font></div><div><span style="color:rgb(5,0,0);font-family:&#39;andale mono&#39;,&#39;lucida console&#39;,monospace;font-size:9.75px;white-space:pre-wrap;background-color:rgb(255,254,254)"><br></span></div><div><span style="background-color:rgb(255,254,254)"><font color="#050000"><span style="white-space:pre-wrap">This expression is expected to produce same output as the examples above. It means check the Optional state of </span></font></span><span style="font-family:monospace">name: String?</span><span style="background-color:rgb(255,254,254)"><font color="#050000"><span style="white-space:pre-wrap">, in case it has a value, unwrap it and make the unwrapped value accessible under the same name to the true condition part of the expression, otherwise return the </span></font></span><span style="color:rgb(5,0,0);white-space:pre-wrap;background-color:rgb(255,254,254)">false </span><span style="white-space:pre-wrap;color:rgb(5,0,0);background-color:rgb(255,254,254)">condition part of the expression.</span></div><div><span style="background-color:rgb(255,254,254)"><font color="#050000"><span style="white-space:pre-wrap"><br></span></font></span></div><div><font color="#050000"><span style="background-color:rgb(255,254,254)"><span style="white-space:pre-wrap">The effectively removes the need to have the &quot;if != nil&quot; and the forced unwrap syntactical code, and IMHO improves code readability and expressiveness.</span></span></font></div><div><font color="#050000"><span style="background-color:rgb(255,254,254)"><span style="white-space:pre-wrap"><br></span></span></font></div><div><div>I&#39;m wondering what the community thinks of the displayed use case, and proposed solution?</div><div><br></div></div><div><br></div><div><font color="#050000"><span style="background-color:rgb(255,254,254)"><span style="white-space:pre-wrap">-m</span></span></font></div></div>