-- | Miscellaneous utility functions
module Data.Record.Internal.Util (
    -- * Monadic combinators
    concatM
  , concatMapM
  ) where

{-------------------------------------------------------------------------------
  Monadic combinators
-------------------------------------------------------------------------------}

concatM :: Applicative m => [m [a]] -> m [a]
concatM :: [m [a]] -> m [a]
concatM = ([[a]] -> [a]) -> m [[a]] -> m [a]
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap [[a]] -> [a]
forall (t :: Type -> Type) a. Foldable t => t [a] -> [a]
concat (m [[a]] -> m [a]) -> ([m [a]] -> m [[a]]) -> [m [a]] -> m [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [m [a]] -> m [[a]]
forall (t :: Type -> Type) (f :: Type -> Type) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA

concatMapM :: Applicative m => (a -> m [b]) -> [a] -> m [b]
concatMapM :: (a -> m [b]) -> [a] -> m [b]
concatMapM a -> m [b]
f = [m [b]] -> m [b]
forall (m :: Type -> Type) a. Applicative m => [m [a]] -> m [a]
concatM ([m [b]] -> m [b]) -> ([a] -> [m [b]]) -> [a] -> m [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> m [b]) -> [a] -> [m [b]]
forall a b. (a -> b) -> [a] -> [b]
map a -> m [b]
f