max<A> function
- Ord<
A> O
Returns a function that returns the maximum of two values.
Example:
void main() {
// Create an Ord instance for integers
Ord<int> ordInt = fromCompare((x, y) => x.compareTo(y));
// Create a function to find the maximum of two integers using the ordInt instance
int Function(int, int) findMax = max(ordInt);
// Find the maximum of two integers
int maxValue = findMax(5, 10); // Output: 10 (Maximum value)
}
Implementation
A Function(A first, A second) max<A>(Ord<A> O) {
return (A first, A second) => O.compare(first, second) > 0 ? first : second;
}