let nums = [20, 2, 4, 5, 8]
func and(_ l: Bool, _ r: () -> Bool) -> Bool {
guard l else { return false }
return r()
}
if and(!nums.isEmpty, { nums[0] > 10 }) {
print(nums[0])
}
func and(_ l: Bool, _ r: @autoclosure () -> Bool) -> Bool {
guard l else { return false }
return r()
}
if and(!nums.isEmpty, nums[0] > 10) {
print(nums[0])
}
网友评论