packages feed

hw-prim 0.6.2.30 → 0.6.2.31

raw patch · 2 files changed

+37/−1 lines, 2 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ HaskellWorks.Control.Monad.Lazy: interleaveTraverseM :: MonadUnliftIO m => (a -> m b) -> [a] -> m [b]
+ HaskellWorks.Control.Monad.Lazy: interleaveUnfoldrM :: MonadUnliftIO m => (b -> m (Maybe (a, b))) -> b -> m [a]

Files

hw-prim.cabal view
@@ -1,7 +1,7 @@ cabal-version:  2.2  name:           hw-prim-version:        0.6.2.30+version:        0.6.2.31 synopsis:       Primitive functions and data types description:    Primitive functions and data types. category:       Data
src/HaskellWorks/Control/Monad/Lazy.hs view
@@ -1,6 +1,9 @@+{-# LANGUAGE BangPatterns #-} module HaskellWorks.Control.Monad.Lazy   ( interleaveSequenceIO   , interleaveSequenceM+  , interleaveUnfoldrM+  , interleaveTraverseM   ) where  import Control.Monad.IO.Unlift@@ -18,3 +21,36 @@ interleaveSequenceM as = do   f <- askUnliftIO   liftIO $ interleaveSequenceIO (fmap (unliftIO f) as)++-- | Generates a lazy list of values that are produced by a given monadic function.+--+-- This function is intended to be like the "standard" 'unfoldrM' except+-- that the list is generated lazily.+interleaveUnfoldrM :: MonadUnliftIO m => (b -> m (Maybe (a, b))) -> b -> m [a]+interleaveUnfoldrM f z = do+  u <- askUnliftIO+  liftIO $ IO.unsafeInterleaveIO (go u z)+  where+    go !u !b = do+      m <- unliftIO u (f b)+      case m of+        Nothing      -> pure []+        Just (!a, b') -> do+          rest <- IO.unsafeInterleaveIO (go u b')+          pure (a:rest)++-- | Traverses the function over the list and produces a lazy list in a+-- monadic context.+--+-- It is intended to be like the "standard" 'traverse' except+-- that the list is generated lazily.+interleaveTraverseM :: MonadUnliftIO m => (a -> m b) -> [a] -> m [b]+interleaveTraverseM f as = do+  u <- askUnliftIO+  liftIO $ IO.unsafeInterleaveIO (go u as)+  where+    go _ [] = pure []+    go !u (v:vs) = do+      !res <- unliftIO u (f v)+      rest <- IO.unsafeInterleaveIO (go u vs)+      pure (res:rest)