Created
June 10, 2014 22:52
-
-
Save kongtomorrow/e153a95907d188fb078a to your computer and use it in GitHub Desktop.
@auto_closure for control over evaluation
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 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