Wondering is it possible to evaluate a simple if statement lazily. Below is an example that will print "this is foo" and "this is bar", but I really want to make it print only the first string:
func foo() {
println("this is foo")
}
func bar() {
println("this is bar")
}
func maybeFooOrBar(isFoo: Bool) {
let myFoo = foo()
let myBar = bar()
isFoo ? myFoo : myBar
}
Do not know if this is what you want,you can use function as a type
Then if you
callmaybeFooOrBar(true)
will print first function,callmaybeFooOrBar(false)
wii print second functionAlso,this can be done in a clear way