module Data.Foldable.Ext ( foldMapAlternative ) where

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

foldMapAlternative :: (Traversable t, Alternative f) => (a -> f b) -> t a -> f b
foldMapAlternative :: forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Alternative f) =>
(a -> f b) -> t a -> f b
foldMapAlternative a -> f b
f t a
xs = forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum (a -> f b
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> t a
xs)