summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libraries/base/Data/Foldable.hs6
-rw-r--r--libraries/base/changelog.md2
2 files changed, 8 insertions, 0 deletions
diff --git a/libraries/base/Data/Foldable.hs b/libraries/base/Data/Foldable.hs
index f5f3112138..cc0f348e47 100644
--- a/libraries/base/Data/Foldable.hs
+++ b/libraries/base/Data/Foldable.hs
@@ -130,6 +130,12 @@ class Foldable t where
-- This INLINE allows more list functions to fuse. See Trac #9848.
foldMap f = foldr (mappend . f) mempty
+ -- | A variant of 'foldMap' that is strict in the accumulator.
+ --
+ -- @since 4.13.0.0
+ foldMap' :: Monoid m => (a -> m) -> t a -> m
+ foldMap' f = foldl' (\ acc a -> acc <> f a) mempty
+
-- | Right-associative fold of a structure.
--
-- In the case of lists, 'foldr', when applied to a binary operator, a
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index 3709a0a1a2..bfa8cb9e18 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -10,6 +10,8 @@
a representational one. There is really no reason to care about the
type of the underlying object.
+ * Add `foldMap'`, a strict version of `foldMap`, to `Foldable`.
+
## 4.12.0.0 *TBA*
* Bundled with GHC *TBA*