Skip to content

Instantly share code, notes, and snippets.

@kongtomorrow
Created June 10, 2014 22:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kongtomorrow/e153a95907d188fb078a to your computer and use it in GitHub Desktop.
Save kongtomorrow/e153a95907d188fb078a to your computer and use it in GitHub Desktop.
@auto_closure for control over evaluation
func myAnd(lhs : Bool, rhs : @auto_closure () -> Bool) -> Bool {
if lhs {
return rhs()
} else {
return false
}
}
func logAndBool(val : Bool) -> Bool {
println("evaluating and returning \(val)!")
return val
}
var res = myAnd(logAndBool(false), logAndBool(true))
// log reads "evaluating and returning false!", does not contain a log for true.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment