Add foldMapM to Data.Foldable

David Feuer david.feuer at gmail.com
Wed Dec 6 23:11:07 UTC 2017


It seems this lazily-accumulating version should be Applicative, and a
strict version Monad. Do we also need a right-to-left version of each?

On Dec 6, 2017 9:29 AM, "Andrew Martin" <andrew.thaddeus at gmail.com> wrote:

Several coworkers and myself have independently reinvented this function
several times:

    foldMapM :: (Foldable g, Monoid b, Monad m) => (a -> m b) -> g a -> m b
    foldMapM f xs = foldlM (\b a -> mappend b <$> (f a)) mempty xs

I would like to propose that this be added to Data.Foldable. We have the
triplet foldr,foldl,foldMap in the Foldable typeclass itself, and
Data.Foldable provides foldrM and foldlM. It would be nice to provide
foldMapM for symmetry and because it seems to be useful in a variety of
applications.

-- 
-Andrew Thaddeus Martin

_______________________________________________
Libraries mailing list
Libraries at haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20171206/e1f4de4e/attachment.html>


More information about the Libraries mailing list