<div dir="ltr">While we’re on the subject, has there been any discussion about adding a pattern matching operator with the polarity reversed?<div><br></div><div>To me at least it seems far more natural to write, eg., “case x =~ somePattern” and to read it as “x matches somePattern” rather than the status quo “somePattern matches x”.</div><div><br></div><div>Nevin</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 3, 2016 at 9:31 PM, Erica Sadun via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></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"><b>Resolved</b>: `if case 1...10 = myNumber { ... }` is an abomination.<div><br></div><div>It confuses inexperience developers. At least those few who are </div><div>aware of its existence. Using the assignment operator for pattern </div><div>matching adds insult to injury. </div><div><br></div><div>I far prefer</div><div> `if case .failure(let error) ~= result { ... } `</div><div>to</div><div><div> `if case .failure(let error) = result {...}`</div></div><div><br></div><div>Though worthy, this isn't a popular pattern. A highly unscientific survey of </div><div>gist reveal:</div><div><br></div><div><div>* Gists using "if case": 94</div><div>* Gists that could use "if let" instead of "if case": Approximately 94-ish</div><div>* Gists using "guard case" (with significant overlap with "if case"): 54</div><div>* Gists that could use "guard let" or "guard x != nil" or "guard x == .enumeration" instead: About 54-ish</div><div>* Standard library: 1 use of "guard case", 5 uses of "if case".</div></div><div><br></div><div><b>Note</b>:</div><div><div><br></div><div>* I love `guard case`/`if case` for `Result` enumerations</div><div>* I love`for case let x? in [optionals]`. </div><div><br></div></div><div><div>I don't expect changing `=` to `~=` would make a huge difference in adoption </div><div>but it would satisfy my inner code critic. Changing it would be breaking</div><div>but as far as I can tell, it wouldn't really break *that* *much* *code*</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-- E</div><div><br></div><div><br></div></font></span></div></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div>