Custom maximumBy and minimumBy in Haskell
Since maximumBy folds a list of elements into a single element, it seems like a perfect candidate to use foldr or foldr1. However, we would need a -&gt; a -&gt; a instead of a -&gt; a -&gt; Ordering.

Let's have a look at maximum first, which can be defined via max :: Ord a =&gt; a -&gt; a -&gt; a:

maximum :: (Foldable t, Ord a) =&gt; t a -&gt; a
maximum = foldr1 max


That looks simple enough to adapt to our myMaximumBy:

myMaximumBy :: (a -&gt; a -&gt; Ordering) -&gt; [a] -&gt; a
myMaximumBy f = foldr1 (maxBy f)


We now only need a maxBy that transforms an a -&gt; a -&gt; Ordering into a a -&gt; a -&gt; a:

maxBy :: (a -&gt; a -&gt; Ordering) -&gt; a -&gt; a -&gt; a
maxBy comp x y = if x `comp` y == LT then y else x


Compared to your original solution, we now


replaced explicit recursion by foldr1
introduced a helper function that can get reused


Our new version is now easier to maintain and use.