contramap<A, B> function
- B f(
- A
Returns a contramap function that transforms an Ord instance based on function f.
Example:
void main() {
// Create an Ord instance for integers
Ord<int> ordInt = fromCompare((x, y) => x.compareTo(y));
// Create a contramap function that transforms the ordInt instance for strings
Ord<String> ordString = contramap((s) => int.parse(s))(ordInt);
// Compare two strings using the ordString instance (after transformation)
int result = ordString.compare('5', '10'); // Output: -1 ('5' is less than '10')
}
Implementation
Ord<A> Function(Ord<B>) contramap<A, B>(B Function(A) f) {
return (Ord<B> fb) => _Ord((A x, A y) => fb.compare(f(x), f(y)));
}