<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>Initially I thought that reswitch (apart from the name :-) looked nice the example of Alex seems to mix two parts of a recursive algorithm into one statement: pattern matching the head of a list and recursing.</div><div><br></div><div>Then I realized that instead of introducing reswitch you can simply extract the switch into a method and call that recursively. This would have the added benefit that instead of "reswitch" the (hopefully) expressive name of the function would be used, making the intent clearer:</div><div><br></div><div>func <b>find</b>(n: T, in list: List<T>) -> Bool {</div><div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"> switch list {</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"> case .Cons(let m, _) where m == n:</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"> return true</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"> case .Cons(_, let rest):</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"> return <b>find</b>(n, in: rest)</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"> case .Empty:</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"> return false</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"> }</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">}</span></font></div></div><div><br></div><div>-Thorsten </div><div><br>Am 06.12.2015 um 22:28 schrieb Alex Lew via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>:<br><br></div><blockquote type="cite"><div>switch lst {</div><div>case .Cons(let m, _) where m == n:</div><div> return true</div><div>case .Cons(_, let rest):</div><div> reswitch(rest)</div><div>case .Empty:</div><div> return false</div><div>}</div></blockquote></body></html>