Skip to content

Instantly share code, notes, and snippets.

@mariogarcia
Created January 24, 2014 08:24
Show Gist options
  • Save mariogarcia/8593878 to your computer and use it in GitHub Desktop.
Save mariogarcia/8593878 to your computer and use it in GitHub Desktop.
Some ideas about negative conditionals
Object.metaClass.not_in = {obj ->
!(delegate in obj)
}
boolean ifnot(boolean val, Closure closure) {
if (!val) {
closure.call()
}
}
def value = 1
def valueList = [3,4,5]
ifnot(value in valueList) {
println "Not in"
}
if (value.not_in(valueList)) {
println "Not in"
} else {
println "in"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment