purescript / purescript-nonempty

A generic non-empty data structure

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add maximum, maximumBy, minimum, minimumBy

sharkdp opened this issue · comments

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)

I think there is some overlap with Foldable1 here.

Do we have Foldable1 somewhere? I was only able to find this PR: purescript/purescript-foldable-traversable#22

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.

Thanks.