Created
June 24, 2015 09:29
-
-
Save cobalamin/05c6f8b4e59d8189b940 to your computer and use it in GitHub Desktop.
Swift operator to flip the values of two variables
This file contains hidden or 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
| 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