Skip to content

Instantly share code, notes, and snippets.

@av-elier
Created October 31, 2016 18:50
Show Gist options
  • Save av-elier/cb69b684fa2ac1a66b2ff805930f074a to your computer and use it in GitHub Desktop.
Save av-elier/cb69b684fa2ac1a66b2ff805930f074a to your computer and use it in GitHub Desktop.
Functional-if-reimplementation.scala
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