Guest User

Untitled

a guest
Jul 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. /// Ignores `value` and just evaluates `pattern`.
  2. /// Can be used to evaluate arbitrary expressions in a switch.
  3. func ~=<A>(pattern: @autoclosure () -> Bool, value: A) -> Bool {
  4. return pattern()
  5. }
  6.  
  7. let (x, y, z) = (0, 0, 1)
  8.  
  9. switch () /* can be anything */ {
  10. case x > 0: print("x matches")
  11. case y < 0: print("y matches")
  12. case z == 1: print("z matches")
  13. default: print("no match")
  14. }
Add Comment
Please, Sign In to add comment