Last active
December 14, 2015 12:50
-
-
Save nemesit/ff6872723b27e373fde5 to your computer and use it in GitHub Desktop.
postfix increment/decrement and prefix increment/decrement, for those who will miss them in Swift 3
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
postfix operator +++ {} | |
postfix func +++(inout left: Int) -> Int { | |
defer {left += 1} | |
return left | |
} | |
postfix operator --- {} | |
postfix func ---(inout left: Int) -> Int { | |
defer {left -= 1} | |
return left | |
} | |
prefix operator +++ {} | |
prefix func +++(inout right: Int) -> Int { | |
right += 1 | |
return right | |
} | |
prefix operator --- {} | |
prefix func ---(inout right: Int) -> Int { | |
right -= 1 | |
return right | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment