Skip to content

Instantly share code, notes, and snippets.

@nartamonov
Created June 1, 2016 10:07
Show Gist options
  • Save nartamonov/2f64998629dcb73853d66504f65ad460 to your computer and use it in GitHub Desktop.
Save nartamonov/2f64998629dcb73853d66504f65ad460 to your computer and use it in GitHub Desktop.
How to define logical operation `not` without conditionals and OOP dispatching
object Bools extends App {
class Bool(negated: () => Bool) {
def not = negated()
}
val True: Bool = new Bool(() => False)
val False: Bool = new Bool(() => True)
assert(True == True)
assert(False == False)
assert(True != False)
assert(True.not == False)
assert(False.not == True)
println("OK")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment