Andrew Martin
2017-12-06 14:28:37 UTC
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.
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
-Andrew Thaddeus Martin