Skip to content

Instantly share code, notes, and snippets.

@hallski
Last active August 29, 2015 14:02
Show Gist options
  • Save hallski/3a2ac40da1471c6dbd03 to your computer and use it in GitHub Desktop.
Save hallski/3a2ac40da1471c6dbd03 to your computer and use it in GitHub Desktop.
Simple ifElse-expression in Swift to try out @auto_closure
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