contramap<A> method
Return an Order instance based on a parameter of type T
extracted from a class A
.
class Parent {
final int value1;
final double value2;
const Parent(this.value1, this.value2);
}
/// Order values of type [Parent] based on their `value1` ([int]).
final orderParentInt = Order.orderInt.contramap<Parent>(
(p) => p.value1,
);
/// Order values of type [Parent] based on their `value2` ([double]).
final orderParentDouble = Order.orderDouble.contramap<Parent>(
(p) => p.value2,
);
Implementation
Order<A> contramap<A>(T Function(A) map) => Order.from<A>(
(a1, a2) => compare(map(a1), map(a2)),
);