Skip to content

Instantly share code, notes, and snippets.

@yugui
Created May 31, 2010 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yugui/419819 to your computer and use it in GitHub Desktop.
Save yugui/419819 to your computer and use it in GitHub Desktop.
trait ExpressionTrueness[T] {
def myElse(then: => T)
}
class ExpressionTruth[T](obj: T) extends ExpressionTrueness[T] {
def myElse(then: => T) = obj
}
class ExpressionFalsity[T] extends ExpressionTrueness[T]() {
def myElse(then: => T) = then
}
def myIf[T](cond: Boolean)(then: => T) : ExpressionTrueness[T] = {
if (cond) {
new ExpressionTruth[T](then)
}
else {
new ExpressionFalsity[T]()
}
}
myIf (1 > 2) { println("true") } myElse { println("false") }
myIf (1 < 2) { println("true") } myElse { println("false") }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment