@JeremyP , &= - AND, . , &&= AND :
infix operator &&= : AssignmentPrecedence
func &&=(lhs: inout Bool, rhs: @autoclosure () -> Bool) {
// although it looks like we're always evaluating rhs here, the expression "rhs()" is
// actually getting wrapped in a closure, as the rhs of && is @autoclosure.
lhs = lhs && rhs()
}
:
func someExpensiveFunc() -> Bool {
// ...
print("some expensive func called")
return false
}
var b = false
b &&= someExpensiveFunc() // someExpensiveFunc() not called, as (false && x) == false.
print(b) // false
b = true
b &&= someExpensiveFunc() // someExpensiveFunc() called, as (true && x) == x
print(b) // false
, rhs: &&= a @autoclosure, , lhs - false.