Foldable.Mapped

Henning Thielemann lemming at henning-thielemann.de
Mon Jan 4 01:11:26 UTC 2016


On Mon, 4 Jan 2016, Oliver Charles wrote:

> Could you provide some examples where you have found it useful?

E.g. Set has Foldable instance, but not Functor. Using Mapped I can 
implement argmax in a generic way, such that it also works on Set.

argmax :: (Ord b, Foldable f) => (a -> b) -> f a -> a
argmax f = snd . Fold.maximumBy (comparing fst) . Mapped (\a -> (f a, a))


More information about the Libraries mailing list