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:

  • None is considered less than any Some<A> value.
  • Two None values are considered equal.
  • Two Some<A> values are compared based on their encapsulated A values.

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
Inheritance

Constructors

OptionOrd(Ord<A> ord)

Properties

hashCode int
The hash code for this object.
read-onlyinherited
ord Ord<A>
final
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited

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