Add maximum, maximumBy, minimum, minimumBy
sharkdp opened this issue · comments
David Peter commented
What about adding small wrappers for the Foldable
functions maximum
, maximumBy
, minimum
, minimumBy
? For NonEmpty
, the return type could be a
instead of Maybe a
:
import Data.Foldable as F
...
-- | Find the smallest element of a non-empty structure, according to its `Ord`
-- | instance.
minimum :: forall a f. (Ord a, Foldable f) => NonEmpty f a -> a
minimum xs@(NonEmpty x _) = fromMaybe x (F.minimum xs)
Phil Freeman commented
I think there is some overlap with Foldable1
here.
David Peter commented
Do we have Foldable1 somewhere? I was only able to find this PR: purescript/purescript-foldable-traversable#22
Matthew Leon commented
Do we have Foldable1 somewhere?
Data.Semigroup.Foldable
. The effect you desire can be achieved with a small lib I wrote here: https://github.com/matthewleon/purescript-semigroups
This issue should probably be closed.
David Peter commented
Thanks.