diff options
author | Simon Jakobi <simon.jakobi@gmail.com> | 2018-10-15 13:55:37 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-10-15 19:24:17 -0400 |
commit | 172b00c1954d8eb609ccd58a731ae89fe74a7489 (patch) | |
tree | 6c3cdbc7560f10e9edba034cb330eb22c0a43970 | |
parent | 45d5eff820aefd42454a7b9f25c4a61dbfca1ad5 (diff) | |
download | haskell-172b00c1954d8eb609ccd58a731ae89fe74a7489.tar.gz |
Add a strict version of foldMap to Foldable
Summary:
Original proposal by Andrew Martin:
https://mail.haskell.org/pipermail/libraries/2018-June/028852.html
Reviewers: andrewthad, hvr, bgamari, alpmestan, tdammers
Reviewed By: bgamari, alpmestan, tdammers
Subscribers: alpmestan, rwbarton, thomie, carter
Differential Revision: https://phabricator.haskell.org/D4924
-rw-r--r-- | libraries/base/Data/Foldable.hs | 6 | ||||
-rw-r--r-- | libraries/base/changelog.md | 2 |
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* |