Skip to content

Instantly share code, notes, and snippets.

@artemnovichkov
Last active April 13, 2018 03:31
Show Gist options
  • Save artemnovichkov/a7c79e6751b76b333b5c2e95975383f7 to your computer and use it in GitHub Desktop.
Save artemnovichkov/a7c79e6751b76b333b5c2e95975383f7 to your computer and use it in GitHub Desktop.
Bitwise AND assignment operator like in Objective-C
func &=(lhs: inout Bool, rhs: @autoclosure () -> Bool) {
lhs = lhs && rhs()
}
infix operator ||=: AssignmentPrecedence
func ||=(lhs: inout Bool, rhs: @autoclosure () -> Bool) {
lhs = lhs || rhs()
}
var bool = true
let array = [1, 2]
bool &= array.count > 1
bool ||= array.count > 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment