packages feed

kempe-0.1.0.1: src/Data/Foldable/Ext.hs

module Data.Foldable.Ext ( foldMapA
                         , foldMapAlternative
                         ) where

import           Control.Applicative (Alternative)
import           Data.Foldable       (asum, fold)

foldMapAlternative :: (Traversable t, Alternative f) => (a -> f b) -> t a -> f b
foldMapAlternative f xs = asum (f <$> xs)

foldMapA :: (Applicative f, Traversable t, Monoid m) => (a -> f m) -> t a -> f m
foldMapA = (fmap fold .) . traverse