4 ms·
In Swift: func myAnd(lhs: Bool, rhs: @autoclosure () -> Bool) -> Bool { return lhs ? rhs() : false } (Heavily inspired by https://
by Someone 11y ago
In Swift:
func myAnd(lhs: Bool,
rhs: @autoclosure () -> Bool) -> Bool
{
return lhs ? rhs() : false
}
(Heavily inspired by https://medium.com/swift-programming/facets-of-swift-part-5-custom-operators-1080bc78ccc#.j2kertet1 https://medium.com/swift-programming/facets-of-swift-part-5-.... Not tested; any bugs likely are mine)
- junke 11y agoI don't know Swift, but it seems[0] that it is not possible to apply this with multiple arguments, like in the original example (e.g. (and a b c d)). [0] https://stackoverflow.com/questions/29750244/variadic-autoclosures-in-swift-1-2 https://stackoverflow.com/questions/29750244/variadic-autocl...