Created
May 31, 2010 13:04
-
-
Save yugui/419819 to your computer and use it in GitHub Desktop.
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
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