Interruptible.hs 692 B

12345678910111213141516171819202122232425262728
  1. {-# LANGUAGE TypeFamilies #-}
  2. module Control.Monad.Trans.Interruptible where
  3. import Control.Monad.Trans.Interruptible.Class
  4. {- |
  5. Folds the second list with the function applied to the first,
  6. intercalating the evaluation. That is:
  7. @
  8. intercalateM f [a00, a10, a20] [b1, b2] = do
  9. a01 <- f a00 b1
  10. a11 <- f a10 b1
  11. a21 <- f a20 b1
  12. a02 <- f a11 b2
  13. a12 <- f a21 b2
  14. a22 <- f a31 b2
  15. return [a02, a12, a22]
  16. @
  17. Usefull for consuming lazy sequences.
  18. -}
  19. intercalateM :: (InterruptibleMonadTrans m, Monad n) => (b -> a -> m n a) -> [b] -> [RDt m a] -> n [RDt m a]
  20. intercalateM _ [] aa = return aa
  21. intercalateM f (b:bb) aa = do
  22. aa' <- mapM (\x -> runT x $ f b) aa
  23. intercalateM f bb aa'