Created
June 1, 2016 10:07
-
-
Save nartamonov/2f64998629dcb73853d66504f65ad460 to your computer and use it in GitHub Desktop.
How to define logical operation `not` without conditionals and OOP dispatching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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