getOrder<T> static method

Order<Option<T>> getOrder<T>(
  1. Order<T> order
)

Return an Order to order instances of Option.

Return 0 when the Options are the same, otherwise uses the given order to compare their values when they are both Some.

Otherwise instances of Some comes before None in the ordering.

Implementation

static Order<Option<T>> getOrder<T>(Order<T> order) => Order.from(
      (a1, a2) => a1 == a2
          ? 0
          : a1
              .flatMap((v1) => a2.flatMap(
                    (v2) => Some(order.compare(v1, v2)),
                  ))
              .getOrElse(() => a1.isSome() ? 1 : -1),
    );