getOrd<A> function

Ord<Option<A>> getOrd<A>(
  1. Ord<A> ord
)

Returns an Ord<Option<A>> based on the provided Ord<A>.

Example usage:

final ordInt = Ord.fromCompare((int x, int y) => x.compareTo(y));
final optionOrdInt = getOrd(ordInt);

assert(optionOrdInt.compare(Some(2), Some(3)) < 0);
assert(optionOrdInt.compare(Some(3), Some(2)) > 0);
assert(optionOrdInt.compare(Some(2), Some(2)) == 0);
assert(optionOrdInt.compare(None(), Some(2)) < 0);
assert(optionOrdInt.compare(Some(2), None()) > 0);
assert(optionOrdInt.compare(None(), None()) == 0);

Implementation

Ord<Option<A>> getOrd<A>(Ord<A> ord) {
  return OptionOrd<A>(ord);
}