module Control.AlternativeExtra (
mmany,
msome,
manyWith,
someWith,
($<)
)where
import Control.Applicative
mmany :: (Alternative a, Monoid m) => a m -> a m
mmany f = foldl mappend mempty <$> many f
msome :: (Alternative a, Monoid m) => a m -> a m
msome f = foldl mappend mempty <$> some f
($<) :: Applicative m => m (a -> b) -> a -> m b
($<) f a = f <*> pure a
manyWith :: (Alternative a, Monoid m) => (v -> m) -> (m -> v) -> a v -> a v
manyWith toMonoid fromMonoid f = fromMonoid <$> (mmany $ toMonoid <$> f)
someWith :: (Alternative a, Monoid m) => (v -> m) -> (m -> v) -> a v -> a v
someWith toMonoid fromMonoid f = fromMonoid <$> (msome $ toMonoid <$> f)