Interruptible.hs 777 B

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