Last active
August 29, 2015 14:02
-
-
Save hallski/3a2ac40da1471c6dbd03 to your computer and use it in GitHub Desktop.
Simple ifElse-expression in Swift to try out @auto_closure
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
func ifElse<T> (f: @auto_closure() -> Bool, ifValue: T, elseValue: T) -> T { | |
if f() { | |
return ifValue; | |
} else { | |
return elseValue; | |
} | |
} | |
let foo = ifElse(12 + 25 > 20, "Yep", "No") // -> foo = "Yep" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment