Method CompareTo
- Namespace
- SodaFlow.Functional
- Assembly
- SodaFlow.Functional.dll
CompareTo(Maybe<T>)
Puts this instance in order against a second one, and a missing value comes first.
public int CompareTo(Maybe<T> other)
Parameters
otherMaybe<T>The instance to compare against.
Returns
- int
A negative number when this sorts before
other, and a positive number when this sorts after it. Zero when no one of the two sorts before the other.
Remarks
No value sorts before each value. That is how
Default puts a Nullable<T>
in order, thus it is the answer with the fewest surprises. This puts two
instances that each have a value in order by
Default for T, which
throws when T has no ordering. That is the same
failure, at the same point, as an order of bare T
values gives.
This reads Default where
operator ==(Maybe<T>, Maybe<T>) reads Default
. Take a type whose ordering and equality disagree, and
string is one: the culture gives its order, and an ordinal
compare gives its equality. Thus, a zero result here does not have to mean
that operator ==(Maybe<T>, Maybe<T>) gives true. This
inherits that from those two comparers, and an order of bare
T values does the same.
There are deliberately no < and > operators to go with
this.
Nullable<T> has them, and they are a trap. They
answer false in the two directions when one side is
missing, thus !(a < b) stops to mean a >= b. A sort is
what needs an ordering, and a sort uses this method.