OptionOrd<A> class
Provides an ordering for Option<A> based on an existing ordering for A.
This is particularly useful when Option<A> values need to be sorted
or otherwise ordered based on the encapsulated value.
Given an ordering for type A (provided by Ord<A>), the ordering for
Option<A> is defined as follows:
Noneis considered less than anySome<A>value.- Two
Nonevalues are considered equal. - Two
Some<A>values are compared based on their encapsulatedAvalues.
Example usage:
final ordInt = IntOrd();
final ordOptionInt = OptionOrd(ordInt);
final result = ordOptionInt.compare(Some(3), Some(5)); // This will return a negative number
final isEqual = ordOptionInt.equals(None(), None()); // This will return true
Properties
Methods
-
compare(
Option< A> x, Option<A> y) → int -
Compares two values and returns an int indicating their order.
inherited
-
equals(
Option< A> x, Option<A> 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