
-- | Compose given list of monadic functions
withFold :: Monad m => [m a -> m a] -> m a -> m a
withFold = foldr (.) id

-- | Turn list into sequence of monadic computations that is then composed
withFoldMap :: Monad m => (a -> m b -> m b) -> [a] -> m b -> m b
withFoldMap f = withFold . map f