-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add {C,c}omparison to Order, fixes #1101
- Loading branch information
Showing
3 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cats.kernel | ||
|
||
/** ADT encoding the possible results of a comparison */ | ||
sealed abstract class Comparison extends Product with Serializable { | ||
/** The signum of this comparison */ | ||
def toInt: Int = this match { | ||
case Comparison.GreaterThan => 1 | ||
case Comparison.EqualTo => 0 | ||
case Comparison.LessThan => -1 | ||
} | ||
} | ||
|
||
object Comparison { | ||
final case object GreaterThan extends Comparison | ||
final case object EqualTo extends Comparison | ||
final case object LessThan extends Comparison | ||
|
||
implicit val catsKernelEqForComparison: Eq[Comparison] = Eq.fromUniversalEquals | ||
} |
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