Closed imcotton closed 1 year ago
Looks solvable with Ord.contramap
?
As an aside I believe the Haskell convention of a "by" suffix is where an Ord
constraint is omitted and a predicate or comparison or what have you is supplied directly instead.
Yes I was thinking about contramap
, however to follow Haskell's convention, do you think it's also necessary to provide
comparing :: (a -> b) -> Ord b -> (a -> a -> Ordering)
as packed deal to compose with
maximumBy :: (a -> a -> Ordering) -> ReadonlyNonEmptyArray a -> a
In this way it aligns to Haskell, but somehow skipped contramap
? Or it's actually just be OK?
If I'm understanding correctly:
maximum(Ord.contramap(f)(o)) = maximumBy(comparing(f)(o))
I personally never interact with Ordering
except in Ord
definitions. contramap
is also more general as it covers all functions taking Ord
, whereas a "By" convention via comparing
requires a new "By" function for each use case (e.g. maximumBy
instead of reusing maximum
).
You are right, on the second thought by having maximum
alongside with contramap
is sufficient enough to cover the usage, I was getting a blind angle between two systems, thanks for help to clarify.
Addition features next to
minimum
andmaximum
, something like: