Created
June 28, 2015 22:48
-
-
Save regnerjr/c81814daabf8097ab07c to your computer and use it in GitHub Desktop.
Method chaining and reducing if statements
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
| extension BooleanLiteralType { | |
| func if_true(block: () -> () ) -> BooleanLiteralType{ | |
| if self { | |
| block() | |
| } | |
| return self | |
| } | |
| func if_false(block: () -> ()) -> BooleanLiteralType { | |
| if !self { | |
| block() | |
| } | |
| return self | |
| } | |
| } | |
| (1 == 1).if_false{print("Help I'm False")} | |
| .if_true{print("Awesome, I'm True")} | |
| (1 == 2).if_true{print("Help I'm True")} | |
| .if_false{print("Sweet, I'm False")} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment