12345678910111213141516171819202122232425262728293031 |
- {-# LANGUAGE TypeFamilies #-}
- module Control.Monad.Trans.Interruptible (
- module Control.Monad.Trans.Interruptible.Class,
- intercalateWith
- )where
- import Control.Monad.Trans.Interruptible.Class
- {- |
- Folds the second list with the function applied to the first,
- intercalating the evaluation. That is:
- @
- intercalateM f [a00, a10, a20] [b1, b2] = do
- a01 <- f a00 b1
- a11 <- f a10 b1
- a21 <- f a20 b1
- a02 <- f a11 b2
- a12 <- f a21 b2
- a22 <- f a31 b2
- return [a02, a12, a22]
- @
- Usefull for consuming lazy sequences.
- -}
- intercalateWith :: Monad m => ((a -> t a) -> rsta -> m (rsta)) -> (b -> a -> t a) -> [b] -> [rsta] -> m [rsta]
- intercalateWith _ _ [] aa = return aa
- intercalateWith res f (b:bb) aa = do
- aa' <- mapM (res $ f b) aa
- intercalateWith res f bb aa'
|