Skip to content

Instantly share code, notes, and snippets.

@nagat01
Created September 2, 2024 12:41
Show Gist options
  • Save nagat01/0776a6af2f07acd9d67ce99852461092 to your computer and use it in GitHub Desktop.
Save nagat01/0776a6af2f07acd9d67ce99852461092 to your computer and use it in GitHub Desktop.
import scala.language.implicitConversions
extension [A](left: A)(using num: Numeric[A])
def >=(right: A) = num.gteq(left, right)
def <=(right: A) = num.lteq(left, right)
def <== (right: A) = (left <= right, right)
def >== (right: A) = (left >= right, right)
extension [A](temp: (Boolean, A))(using num: Numeric[A])
def <== (right: A) = (temp._1 && temp._2 <= right, right)
def >== (right: A) = (temp._1 && temp._2 >= right, right)
// implicit def boolNumberToBool[A](temp: (Boolean, A)): Boolean = temp._1
given [A]: Conversion[(Boolean, A), Boolean] = temp => temp._1
@main def main =
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment