<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 &nbsp;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&lt;T&gt;) -&gt; Bool {</div><div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; switch list {</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; case .Cons(let m, _) where m == n:</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; &nbsp; &nbsp; return true</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; case .Cons(_, let rest):</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; &nbsp; &nbsp; return&nbsp;<b>find</b>(n, in: rest)</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; case .Empty:</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; &nbsp; &nbsp; return false</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; }</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&nbsp;</div><div><br>Am 06.12.2015 um 22:28 schrieb Alex Lew via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;:<br><br></div><blockquote type="cite"><div>switch lst {</div><div>case .Cons(let m, _) where m == n:</div><div>&nbsp; &nbsp; &nbsp;return true</div><div>case .Cons(_, let rest):</div><div>&nbsp; &nbsp; reswitch(rest)</div><div>case .Empty:</div><div>&nbsp; &nbsp; &nbsp;return false</div><div>}</div></blockquote></body></html>