Skip to content

Instantly share code, notes, and snippets.

@nagat01
Created December 9, 2015 05:09
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 nagat01/88568e059b554218350a to your computer and use it in GitHub Desktop.
Save nagat01/88568e059b554218350a to your computer and use it in GitHub Desktop.
object Example {
implicit class NumberEx[A](val left:A)(implicit num:Numeric[A]) {
def <== (right:A) = (num.lteq(left, right), right)
def >== (right:A) = (num.gteq(left, right), right)
}
implicit class BoolNumberEx[A](val temp:(Boolean, A))(implicit num:Numeric[A]) {
def <== (right:A) = (temp._1 & num.lteq(temp._2, right), right)
def >== (right:A) = (temp._1 & num.gteq(temp._2, right), right)
}
implicit def boolNumberToBool[A](temp:(Boolean, A)) = temp._1
def main(args: Array[String]) {
val x = 15
if(10 <== x <== 20) println(1)
if(20 <== x <== 10) println(2)
if(30 >== x*2 >== 20 >== x) println(3)
if(15 >== x <== 15) println(4)
}
// result:
// 1
// 3
// 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment