trait PartialOrder[A] extends Eq[A]
The PartialOrder
type class is used to define a partial ordering on some type A
.
A partial order is defined by a relation <=, which obeys the following laws:
- x <= x (reflexivity)
- if x <= y and y <= x, then x = y (anti-symmetry)
- if x <= y and y <= z, then x <= z (transitivity)
To compute both <= and >= at the same time, we use a Double number to encode the result of the comparisons x <= y and x >= y. The truth table is defined as follows:
x <= y | x >= y | result | note |
---|---|---|---|
true | true | 0.0 | (corresponds to x = y) |
false | false | NaN | (x and y cannot be compared) |
true | false | -1.0 | (corresponds to x < y) |
false | true | 1.0 | (corresponds to x > y) |
- Self Type
- PartialOrder[A]
- Source
- PartialOrder.scala
- Alphabetic
- By Inheritance
- PartialOrder
- Eq
- Serializable
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def getClass(): Class[_ <: AnyRef]
- Definition Classes
- Any
- abstract def partialCompare(x: A, y: A): Double
Result of comparing
x
withy
.Result of comparing
x
withy
. Returns NaN if operands are not comparable. If operands are comparable, returns a Double whose sign is:- negative iff
x < y
- zero iff
x = y
- positive iff
x > y
- negative iff
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- Any
- final def ##: Int
- Definition Classes
- Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def equals(arg0: Any): Boolean
- Definition Classes
- Any
- def eqv(x: A, y: A): Boolean
Returns true if
x
=y
, false otherwise.Returns true if
x
=y
, false otherwise.- Definition Classes
- PartialOrder → Eq
- def gt(x: A, y: A): Boolean
Returns true if
x
>y
, false otherwise. - def gteqv(x: A, y: A): Boolean
Returns true if
x
>=y
, false otherwise. - def hashCode(): Int
- Definition Classes
- Any
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def lt(x: A, y: A): Boolean
Returns true if
x
<y
, false otherwise. - def lteqv(x: A, y: A): Boolean
Returns true if
x
<=y
, false otherwise. - def neqv(x: A, y: A): Boolean
Returns
false
ifx
andy
are equivalent,true
otherwise.Returns
false
ifx
andy
are equivalent,true
otherwise.- Definition Classes
- Eq
- def partialComparison(x: A, y: A): Option[Comparison]
Like
partialCompare
, but returns a cats.kernel.Comparison instead of an Double.Like
partialCompare
, but returns a cats.kernel.Comparison instead of an Double. Has the benefit of being able to pattern match on, but not as performant. - def pmax(x: A, y: A): Option[A]
Returns Some(x) if x >= y, Some(y) if x < y, otherwise None.
- def pmin(x: A, y: A): Option[A]
Returns Some(x) if x <= y, Some(y) if x > y, otherwise None.
- def toString(): String
- Definition Classes
- Any
- def tryCompare(x: A, y: A): Option[Int]
Result of comparing
x
withy
.Result of comparing
x
withy
. Returns None if operands are not comparable. If operands are comparable, returns Some[Int] where the Int sign is:- negative iff
x < y
- zero iff
x = y
- positive iff
x > y
- negative iff