Skip to content

Instantly share code, notes, and snippets.

@cobalamin
Created June 24, 2015 09:29
Show Gist options
  • Select an option

  • Save cobalamin/05c6f8b4e59d8189b940 to your computer and use it in GitHub Desktop.

Select an option

Save cobalamin/05c6f8b4e59d8189b940 to your computer and use it in GitHub Desktop.
Swift operator to flip the values of two variables
infix operator >!< {
associativity left
precedence 140
}
func >!<<T>(inout a: T, inout b: T) {
(a, b) = (b, a)
}
// example:
var a = 42 // 42
var b = 1337 // 1337
a >!< b
a // 1337
b // 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment