<html><head><style>
body {
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        padding:1em;
        margin:auto;
        background:#fefefe;
}

h1, h2, h3, h4, h5, h6 {
        font-weight: bold;
}

h1 {
        color: #000000;
        font-size: 28pt;
}

h2 {
        border-bottom: 1px solid #CCCCCC;
        color: #000000;
        font-size: 24px;
}

h3 {
        font-size: 18px;
}

h4 {
        font-size: 16px;
}

h5 {
        font-size: 14px;
}

h6 {
        color: #777777;
        background-color: inherit;
        font-size: 14px;
}

hr {
        height: 0.2em;
        border: 0;
        color: #CCCCCC;
        background-color: #CCCCCC;
    display: inherit;
}

p, blockquote, ul, ol, dl, li, table, pre {
        margin: 15px 0;
}

a, a:visited {
        color: #4183C4;
        background-color: inherit;
        text-decoration: none;
}

#message {
        border-radius: 6px;
        border: 1px solid #ccc;
        display:block;
        width:100%;
        height:60px;
        margin:6px 0px;
}

button, #ws {
        font-size: 12 pt;
        padding: 4px 6px;
        border-radius: 5px;
        border: 1px solid #bbb;
        background-color: #eee;
}

code, pre, #ws, #message {
        font-family: Monaco;
        font-size: 10pt;
        border-radius: 3px;
        background-color: #F8F8F8;
        color: inherit;
}

code {
        border: 1px solid #EAEAEA;
        margin: 0 2px;
        padding: 0 5px;
}

pre {
        border: 1px solid #CCCCCC;
        overflow: auto;
        padding: 4px 8px;
}

pre > code {
        border: 0;
        margin: 0;
        padding: 0;
}

#ws { background-color: #f8f8f8; }


.bloop_markdown table {
border-collapse: collapse;  
font-family: Helvetica, arial, freesans, clean, sans-serif;  
color: rgb(51, 51, 51);  
font-size: 15px; line-height: 25px;
padding: 0; }

.bloop_markdown table tr {
border-top: 1px solid #cccccc;
background-color: white;
margin: 0;
padding: 0; }
     
.bloop_markdown table tr:nth-child(2n) {
background-color: #f8f8f8; }

.bloop_markdown table tr th {
font-weight: bold;
border: 1px solid #cccccc;
margin: 0;
padding: 6px 13px; }

.bloop_markdown table tr td {
border: 1px solid #cccccc;
margin: 0;
padding: 6px 13px; }

.bloop_markdown table tr th :first-child, table tr td :first-child {
margin-top: 0; }

.bloop_markdown table tr th :last-child, table tr td :last-child {
margin-bottom: 0; }

.bloop_markdown blockquote{
  border-left: 4px solid #dddddd;
  padding: 0 15px;
  color: #777777; }
  blockquote > :first-child {
    margin-top: 0; }
  blockquote > :last-child {
    margin-bottom: 0; }

code, pre, #ws, #message {
    word-break: normal;
    word-wrap: normal;
}

hr {
    display: inherit;
}

.bloop_markdown :first-child {
    -webkit-margin-before: 0;
}

code, pre, #ws, #message {
    font-family: Menlo, Consolas, Liberation Mono, Courier, monospace;
}


.send { color:#77bb77; }
.server { color:#7799bb; }
.error { color:#AA0000; }</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="bloop_markdown"><p>I forgot about map :D That solution is more swifty than mine with <code>String(format::)</code>.</p>

<p></p></div><div class="bloop_original_html"><style>body{font-family:Helvetica,Arial;font-size:13px}</style><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div> <br> <div id="bloop_sign_1486567297132636928" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">--&nbsp;<br>Adrian Zubarev<br>Sent with Airmail</div></div> <br><p class="airmail_on">Am 8. Februar 2017 um 16:12:11, Tony Allevato via swift-evolution (<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>) schrieb:</p> <blockquote type="cite" class="clean_bq"><span><div><div></div><div>


<title></title>


<div dir="ltr">What you're asking for is already possible (avoiding
the optional unwrap) by combining map() on Optional with ??:
<div><br></div>
<div>```</div>
<div>
<div>let name1: String? = "name"</div>
<div>print(name1.map { "\"\($0)\"" } ?? "null") &nbsp;// prints
"\"name\""</div>
<div><br></div>
<div>let name2: String? = nil</div>
<div>print(name2.map { "\"\($0)\"" } ?? "null") &nbsp;// prints
"null"</div>
<div>```</div>
<div><br></div>
<div>So I guess the question is, does simplifying that rise to the
level of wanting a custom operator? I personally don't think it
does, but I could see an argument being made that an operator with
defined semantics might be a small amount clearer than map&nbsp;+
??. But I think the benefits would have to be very strong,
though.</div>
<div><br></div>
<div>And as other folks have mentioned, having "!" in the operator
name is somewhat misleading, since when I see that I expect a trap
to occur in nil cases.</div>
<div><br></div>
<div><br></div>
<br>
<div class="gmail_quote">
<div dir="ltr">On Wed, Feb 8, 2017 at 6:04 AM Maxim Veksler via
swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;
wrote:<br></div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr" class="gmail_msg">Hello,&nbsp;
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">Let's assume I have an optional "name"
parameter, based on the optional status of the parameters I would
like to compose string with&nbsp;either the unwrapped value of
name, or the string "null". The use case for is syntactic sugar to
compose a GraphQL queries.<br class="gmail_msg"></div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">A (sampled) illustration of the code that
currently solves it looks as following:</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">
<div class="gmail_msg"><font face="monospace" class="gmail_msg">func query(name: String?) {</font></div>
<div class="gmail_msg"><font face="monospace" class="gmail_msg">&nbsp;&nbsp;<span style="color:rgb(5,0,0);font-size:9.75px;white-space:pre-wrap;background-color:rgb(255,254,254)" class="gmail_msg">let variables_name = name != nil ? "\"\(name!)\""
: "null"</span></font></div>
<div class="gmail_msg"><font face="monospace" class="gmail_msg"><span style="color:rgb(5,0,0);font-size:9.75px;white-space:pre-wrap;background-color:rgb(255,254,254)" class="gmail_msg">return "{ param: \(</span><span style="color:rgb(5,0,0);font-size:9.75px;white-space:pre-wrap;background-color:rgb(255,254,254)" class="gmail_msg">variables_name</span><span style="color:rgb(5,0,0);font-size:9.75px;white-space:pre-wrap;background-color:rgb(255,254,254)" class="gmail_msg">) }"</span></font></div>
<div class="gmail_msg"><span style="font-family:monospace;color:rgb(5,0,0);font-size:9.75px;white-space:pre-wrap;background-color:rgb(255,254,254)" class="gmail_msg">}</span><br class="gmail_msg"></div>
</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">Based on optional status the following
output is expected</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg"><font face="monospace" class="gmail_msg">let
name = "Max"</font></div>
<div class="gmail_msg"><font face="monospace" class="gmail_msg">query(name: name)&nbsp;</font></div>
<div class="gmail_msg"><font face="monospace" class="gmail_msg">//
{ param: "Max" }</font></div>
<div class="gmail_msg"><font face="monospace" class="gmail_msg"><br class="gmail_msg"></font></div>
<div class="gmail_msg"><font face="monospace" class="gmail_msg">let
name: String? = nil</font></div>
<div class="gmail_msg"><font face="monospace" class="gmail_msg">query(name: name)</font></div>
<div class="gmail_msg"><font face="monospace" class="gmail_msg">//
{ param: null }</font></div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">I think it might be useful to have an
conditional unwrap operator <font face="monospace" class="gmail_msg">!?</font> that would enable syntax sugar uch as the
following built into the language:</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg"><font face="monospace" class="gmail_msg">func query(name: String?) {</font></div>
<div class="gmail_msg"><font face="monospace" class="gmail_msg">&nbsp;&nbsp;<span style="color:rgb(5,0,0);font-size:9.75px;white-space:pre-wrap;background-color:rgb(255,254,254)" class="gmail_msg">return "{ param: \(name !? "\"\(name)\"": "null")
}"</span></font></div>
<div class="gmail_msg"><font face="monospace" class="gmail_msg"><span style="color:rgb(5,0,0);font-size:9.75px;white-space:pre-wrap;background-color:rgb(255,254,254)" class="gmail_msg">}</span><br class="gmail_msg"></font></div>
<div class="gmail_msg"><span style="color:rgb(5,0,0);font-family:'andale mono','lucida console',monospace;font-size:9.75px;white-space:pre-wrap;background-color:rgb(255,254,254)" class="gmail_msg"><br class="gmail_msg"></span></div>
<div class="gmail_msg"><span style="background-color:rgb(255,254,254)" class="gmail_msg"><font color="#050000" class="gmail_msg"><span style="white-space:pre-wrap" class="gmail_msg">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" class="gmail_msg">name: String?</span><span style="background-color:rgb(255,254,254)" class="gmail_msg"><font color="#050000" class="gmail_msg"><span style="white-space:pre-wrap" class="gmail_msg">, 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&nbsp;</span></font></span><span style="color:rgb(5,0,0);white-space:pre-wrap;background-color:rgb(255,254,254)" class="gmail_msg">false</span> <span style="white-space:pre-wrap;color:rgb(5,0,0);background-color:rgb(255,254,254)" class="gmail_msg">condition part of the expression.</span></div>
<div class="gmail_msg"><span style="background-color:rgb(255,254,254)" class="gmail_msg"><font color="#050000" class="gmail_msg"><span style="white-space:pre-wrap" class="gmail_msg"><br class="gmail_msg"></span></font></span></div>
<div class="gmail_msg"><font color="#050000" class="gmail_msg"><span style="background-color:rgb(255,254,254)" class="gmail_msg"><span style="white-space:pre-wrap" class="gmail_msg">The effectively removes the need to have the "if !=
nil" and the forced unwrap syntactical code, and IMHO improves code
readability and expressiveness.</span></span></font></div>
<div class="gmail_msg"><font color="#050000" class="gmail_msg"><span style="background-color:rgb(255,254,254)" class="gmail_msg"><span style="white-space:pre-wrap" class="gmail_msg"><br class="gmail_msg"></span></span></font></div>
<div class="gmail_msg">
<div class="gmail_msg">I'm wondering what the community thinks of
the displayed use case, and proposed solution?</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg"><font color="#050000" class="gmail_msg"><span style="background-color:rgb(255,254,254)" class="gmail_msg"><span style="white-space:pre-wrap" class="gmail_msg">-m</span></span></font></div>
</div>
_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote>
</div>
</div>
</div>


_______________________________________________<br>swift-evolution mailing list<br>swift-evolution@swift.org<br>https://lists.swift.org/mailman/listinfo/swift-evolution<br></div></div></span></blockquote></div><div class="bloop_markdown"><p></p></div></body></html>