Proposal: add ordNub somewhere in containers
Henning Thielemann
lemming at henning-thielemann.de
Tue Oct 17 09:54:53 UTC 2017
On Tue, 17 Oct 2017, Henning Thielemann wrote:
> ordNub could be implemented using Traversable:
>
> catMaybes (traverse ??? xs :: [Maybe a])
>
> You would only need a generalization for catMaybes like mfilter.
ordNub :: (Traversable f, MonadPlus f, Ord a) => f a -> f a
ordNub =
join . snd .
Trav.mapAccumL
(\s x ->
if Set.member x s
then (s,mzero)
else (Set.insert x s, return x))
Set.empty
We don't need mplus, only Monad and mzero.
More information about the Libraries
mailing list