[swift-evolution] Proposal: Remove the "fallthrough" keyword
thorsten at portableinnovations.de
thorsten at portableinnovations.de
Sun Dec 6 16:03:21 CST 2015
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.
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:
func find(n: T, in list: List<T>) -> Bool {
switch list {
case .Cons(let m, _) where m == n:
return true
case .Cons(_, let rest):
return find(n, in: rest)
case .Empty:
return false
}
}
-Thorsten
> Am 06.12.2015 um 22:28 schrieb Alex Lew via swift-evolution <swift-evolution at swift.org>:
>
> switch lst {
> case .Cons(let m, _) where m == n:
> return true
> case .Cons(_, let rest):
> reswitch(rest)
> case .Empty:
> return false
> }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151206/28e4cb62/attachment.html>
More information about the swift-evolution
mailing list