Skip to content

Instantly share code, notes, and snippets.

@bandrzejczak
Created February 9, 2018 21:53
Show Gist options
  • Save bandrzejczak/0ba598742ec14820999eec5be72a03c2 to your computer and use it in GitHub Desktop.
Save bandrzejczak/0ba598742ec14820999eec5be72a03c2 to your computer and use it in GitHub Desktop.
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