<div dir="ltr">Thanks Austin,<div><br></div><div><div><b>let myThing = {</b></div><div><b>  if someCondition {</b></div><div><b>    return 1</b></div><div><b>  } else {</b></div><div><b>    return 2</b></div><div><b>  }</b></div><div><b>}()</b></div></div><div><br></div><div>While that is ugly, it does have the benefit of being crystal clear about its intent (i.e.: setting &quot;myThing&quot;) since everything after the first line is going to be indented.</div><div><br></div><div>What I dislike about using a &quot;switch&quot; to achieve the same thing is rereading my code. It can take a couple moments to clue in that its just assigning, and to realize there&#39;s nothing *else* going on in the &quot;switch&quot; aside from the assignment. </div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 4, 2016 at 11:04 PM, Austin Zheng <span dir="ltr">&lt;<a href="mailto:austinzheng@gmail.com" target="_blank">austinzheng@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span class="">There was a popular pattern which went as follows:<div><br></div><div>let myThing = {</div><div>  if someCondition {</div><div>    return 1</div><div>  } else {</div><div>    return 2</div><div>  }</div><div>}()</div><div><br></div><div>It&#39;s a little ugly, but the compiler is apparently smart enough to inline/optimize away the anonymous closure. It became less popular once Swift got support for declaring lets without an initial value.</div><div><br></div><div>Austin</div><div><br></div></span><div><blockquote type="cite"><span class=""><div>On Jan 4, 2016, at 10:55 PM, Charles Constant via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br></span><span class=""><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div><span style="font-size:13px">My best guesses here, since I didn&#39;t write and don&#39;t entirely agree...</span></div><div><span style="font-size:13px"><br></span></div><div><b><span style="font-size:13px">&gt; </span><span style="font-size:13px">Please detail what the trade offs are</span></b></div><span style="font-size:13px"><div><span style="font-size:13px"><br></span></div><div>Other than more complexity, I think this refers to making the &quot;switch&quot; statement do two slightly different things. Of course, if we call it something else, like &quot;match&quot; or &quot;which&quot; then it stops being an issue.</div><div><span style="font-size:13px"><br></span></div><b>&gt; What are the other ways that Swift currently supports this?</b></span><br><div><span style="font-size:13px"><br></span></div><div>As far as I can see, the closest we get are...</div><div><br></div><div>    a) The existing &quot;switch&quot; statement, or if else statement (preceded with a statement to declare the variable. yuck). I think this is verbose enough to qualify as &quot;confusing&quot;</div><div><br></div><div>    b) Creating an anonymous dict, and immediately accessing it (which means the keys need to be Hashable). This isn&#39;t very flexible</div><div><br></div><div>    c) Creating a special init or function, to map one enum, to another. This  is also verbose, and not flexible, and moves the code away from where it used (even if you never reuse the mapping).</div><div><br></div><div>    d) Chaining a bunch of conditions in a ternary... Horrible.</div><div><br></div><div>Anyone know of any better alternatives? It feels like I&#39;m missing something.</div><div><br></div></div></div></span></blockquote></div><br></div></blockquote></div><br></div>