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

Add a strict version of foldMap to Foldable

Original proposal by Andrew Martin:

Reviewers: andrewthad, hvr, bgamari, alpmestan, tdammers

Reviewed By: bgamari, alpmestan, tdammers

Subscribers: alpmestan, rwbarton, thomie, carter

Differential Revision:
parent 45d5eff8
......@@ -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
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
......@@ -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`.
## *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