<div dir="ltr"><div style="font-size:12.8px">Hi all,</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Swift has a pattern match operator, ~=, which is unknown to many (like me until a few weeks ago), that performs a match between a value and a certain pattern, e.g. checking if an integer value is contained in a range of integers.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">This operator may be little known, but it plays a key role in the language since it&#39;s used behind the scenes to support expression patterns in `switch` statement case labels, which we all know are extremely popular.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">let point = (2, 4)</div><div style="font-size:12.8px">switch point {</div><div style="font-size:12.8px">case (0, 0):</div><div style="font-size:12.8px">    print(&quot;The point is at the origin&quot;)</div><div style="font-size:12.8px">case (0...4, 0...4):</div><div style="font-size:12.8px">    print(&quot;The point is in the subregion&quot;)</div><div style="font-size:12.8px">default:</div><div style="font-size:12.8px">    break</div><div style="font-size:12.8px">}</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Most of the time we don&#39;t use the operator directly but it is available and can be handy in certain conditions.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">let point = (2, 4)</div><div style="font-size:12.8px">switch point {</div><div style="font-size:12.8px">case (let x, let y) where 0...4 ~= x &amp;&amp; 0...4 ~= y:</div><div style="font-size:12.8px">    print(&quot;The point is in the subregion&quot;)</div><div style="font-size:12.8px">default:</div><div style="font-size:12.8px">    break</div><div style="font-size:12.8px">}</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">However the current syntax is not ideal (in my opinion). We&#39;re not really declaring the operation that we want to do, and that has an impact in the expressivity and readability of the code. Currently we&#39;re doing matches like &quot;if blue is the ocean&quot; instead of &quot;if the ocean is blue&quot; or &quot;if the ocean contains the whale&quot; instead of &quot;if the whale is in the ocean&quot;.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">For that reason, I would like to suggest inverting the order of the operator to match more closely our logical thought.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">case (let x, let y) where x =~ 0...4 &amp;&amp; y =~ 0...4: // Proposed</div><div style="font-size:12.8px">// vs</div><div style="font-size:12.8px">case (let x, let y) where 0...4 ~= x &amp;&amp; 0...4 ~= y: // Current</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I have an ongoing proposal to suggest this change and it contains a little more context. It is available here: </div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><a href="https://github.com/dmcrodrigues/swift-evolution/blob/proposal/invert-order-of-pattern-match-operator/proposals/NNNN-invert-order-of-pattern-match-operator.md" target="_blank">https://github.com/dmcrodrigues/swift-evolution/blob/proposal/invert-order-of-pattern-match-operator/proposals/NNNN-invert-order-of-pattern-match-operator.md</a>.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Any feedback is very welcome.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Thank you.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">David Rodrigues</div></div>