Created
October 31, 2016 18:50
-
-
Save av-elier/cb69b684fa2ac1a66b2ff805930f074a to your computer and use it in GitHub Desktop.
Functional-if-reimplementation.scala
This file contains 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
def `if`[T](cond: Boolean) = { | |
class Then(cond: Boolean, t: => T) { | |
def `else`(elseF: => T): T= if (!cond) elseF else t | |
} | |
def `then`(thenF: => T) = new Then(cond, thenF) | |
`then` _ | |
} | |
`if` (2*2 == 4) { | |
println("then") | |
} `else` { | |
println("else") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment