Created
December 9, 2015 05:09
-
-
Save nagat01/88568e059b554218350a to your computer and use it in GitHub Desktop.
This file contains 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 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