Last active
August 7, 2018 10:47
-
-
Save ole/a369f6a145235a28b5c4d6e4b1ac8dba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Ignores `value` and just evaluates `pattern`. | |
/// Can be used to evaluate arbitrary expressions in a switch. | |
func ~=<A>(pattern: @autoclosure () -> Bool, value: A) -> Bool { | |
return pattern() | |
} | |
let (x, y, z) = (0, 0, 1) | |
switch () /* can be anything */ { | |
case x > 0: print("x matches") | |
case y < 0: print("y matches") | |
case z == 1: print("z matches") | |
default: print("no match") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment