Commit 172b00c1 authored by Simon Jakobi's avatar Simon Jakobi Committed by Ben Gamari
Browse files

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
parent 45d5eff8
...@@ -130,6 +130,12 @@ class Foldable t where ...@@ -130,6 +130,12 @@ class Foldable t where
-- This INLINE allows more list functions to fuse. See Trac #9848. -- This INLINE allows more list functions to fuse. See Trac #9848.
foldMap f = foldr (mappend . f) mempty 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. -- | Right-associative fold of a structure.
-- --
-- In the case of lists, 'foldr', when applied to a binary operator, a -- In the case of lists, 'foldr', when applied to a binary operator, a
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
a representational one. There is really no reason to care about the a representational one. There is really no reason to care about the
type of the underlying object. type of the underlying object.
* Add `foldMap'`, a strict version of `foldMap`, to `Foldable`.
## 4.12.0.0 *TBA* ## 4.12.0.0 *TBA*
* Bundled with GHC *TBA* * Bundled with GHC *TBA*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment