File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
src/main/scala/fpspeedrun Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -5,11 +5,10 @@ import fpspeedrun.Ord.Compare._
55final case class Ratio (numer : Int , denom : Int )
66
77object Ratio {
8- implicit val eqRatio : Eq [Ratio ] =
9- (x : Ratio , y : Ratio ) => x.numer * y.denom == y.numer * x.denom
108
119 implicit val ordRatio : Ord [Ratio ] = new Ord [Ratio ] {
12- override def === (x : Ratio , y : Ratio ): Boolean = eqRatio.=== (x, y)
10+ override def === (x : Ratio , y : Ratio ): Boolean =
11+ x.numer * y.denom == y.numer * x.denom
1312
1413 override def compare (x : Ratio , y : Ratio ): Ord .Compare =
1514 if (=== (x, y)) EQ
Original file line number Diff line number Diff line change 11package fpspeedrun
22
3+ import fpspeedrun .Ord .Compare ._
4+
35object syntax {
46 object eq {
57 implicit class EqOps [T ](val x : T ) extends AnyVal {
@@ -9,6 +11,17 @@ object syntax {
911 object compare {
1012 implicit class CompareOps [T ](val x : T ) extends AnyVal {
1113 def compare (y : T )(implicit ord : Ord [T ]): Ord .Compare = ord.compare(x, y)
14+
15+ def > (y : T )(implicit ord : Ord [T ]): Boolean = compare(y) == GT
16+ def < (y : T )(implicit ord : Ord [T ]): Boolean = compare(y) == LT
17+ def >= (y : T )(implicit ord : Ord [T ]): Boolean = {
18+ val c = compare(y)
19+ c == GT || c == EQ
20+ }
21+ def <= (y : T )(implicit ord : Ord [T ]): Boolean = {
22+ val c = compare(y)
23+ c == LT || c == EQ
24+ }
1225 }
1326 }
1427}
You can’t perform that action at this time.
0 commit comments