<div dir="ltr"><div>Would anyone be interested in &quot;where&quot; (or a similar keyword or operator) being able to do this:<br></div><div><br></div><div><div>    <b>let val = &quot;foo&quot; where true</b> // &quot;foo&quot;</div></div><div><div>    <b>let val = &quot;foo&quot; where false</b> // nil</div></div><div><br></div><div>... and therefore being able to work in conjunction like this:</div><div><br></div><div><b>    let val = </b></div><div><b>        &quot;positive&quot; where ( val &gt; 0 )  ?? </b></div><div><b>        &quot;negative&quot; where ( val &lt; 0 ) ?? </b></div><div><b>        &quot;zero&quot;</b></div><div><br></div><div>In other words, a statement that given a value and a bool, and returns the value if the bool is true, but nil if the bool is false.</div><div><br></div>There have been a few threads here about &quot;switch assignment&quot; and &quot;extended ternary&quot; statements. I encounter frustrations regularly when I want to write concise, but easy-to-read code for conditions that require more to than two options. We have discussed problems using dicts, enums, etc in the past. <div><br></div><div>The problem with most of the suggestions so far is that they aren&#39;t very Swifty. But if &quot;where&quot; worked the way I&#39;m pitching, a coder could impliment most of the alternatives we&#39;ve discussed (by using autoclosure, and custom operators). Eg:</div><div><br></div><div><b>    let val:FooEnum = depends( bar ){</b></div><div><b>        .Red where $0 == .A  ?? </b></div><div><b>        .Blue where $0 == .B ?? </b></div><div><b>        .Green where $0 == .C ?? </b></div><div><b>        .None<br></b></div><div><b>    }</b><br></div><div><br></div><div>This strikes me as the least disruptive, and most Swifty solution.</div><div><br></div><div>Would this appeal to anyone else?</div></div>