Created
February 9, 2018 21:53
-
-
Save bandrzejczak/0ba598742ec14820999eec5be72a03c2 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
object ScalarTernaryTyped extends App{ | |
class TernaryIfThenClause[X](c: => Boolean, tc: => X){ | |
lazy val cond = c | |
lazy val thenClause = tc | |
} | |
implicit class TernaryAssoc(cond: => Boolean){ | |
def ??[X](thenClause: => X) = new TernaryIfThenClause(cond, thenClause) | |
} | |
implicit class TernaryElseClause[X](elseClause: => X){ | |
def ::(ifThenClause: TernaryIfThenClause[X]) = | |
if(ifThenClause.cond) ifThenClause.thenClause else elseClause | |
} | |
println((1 + 1 == 2) ?? "True" :: "False") | |
println((1 + 5 == 2) ?? "True" :: "False") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment