EitherOrd<A, B> class
A class that extends Ord
to provide a custom ordering for Either
values.
This class provides a way to compare two Either
values based on the
provided orderings for the Left
and Right
types.
If both Either
values are Left
, they are compared using the provided
leftOrd
. If both are Right
, they are compared using the provided rightOrd
.
If one is Left
and the other is Right
, Left
is considered to come before Right
.
Example usage:
final intOrder = Ord<int>((a, b) => a.compareTo(b));
final strOrder = Ord<String>((a, b) => a.compareTo(b));
final eitherOrder = EitherOrd(intOrder, strOrder);
final e1 = Left<int, String>(3);
final e2 = Left<int, String>(5);
final e3 = Right<int, String>("apple");
final e4 = Right<int, String>("banana");
print(eitherOrder.compare(e1, e2)); // -1 because 3 < 5
print(eitherOrder.compare(e3, e4)); // -1 because "apple" < "banana"
print(eitherOrder.compare(e1, e3)); // -1 because Left always comes before Right
Constructors
Properties
Methods
-
compare(
Either< A, B> x, Either<A, B> y) → int -
Compares two values and returns an int indicating their order.
inherited
-
equals(
Either< A, B> x, Either<A, B> y) → bool -
Returns true if the two values are equal according to the compare function.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited