From 57a78945dfdb321ae7656165b6349f3539456680 Mon Sep 17 00:00:00 2001 From: ocramz Date: Sun, 22 Nov 2020 18:18:43 +0100 Subject: [PATCH 1/6] add foldWhile --- conduit/src/Data/Conduit/Combinators.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/conduit/src/Data/Conduit/Combinators.hs b/conduit/src/Data/Conduit/Combinators.hs index a2e1f07eb..2682f15e4 100644 --- a/conduit/src/Data/Conduit/Combinators.hs +++ b/conduit/src/Data/Conduit/Combinators.hs @@ -1755,6 +1755,22 @@ mapAccumWhileC f = {-# INLINE mapAccumWhileC #-} STREAMING(mapAccumWhile, mapAccumWhileC, mapAccumWhileS, f s) + +-- | Specialized version of 'mapAccumWhile' that does not provide values downstream. +-- +-- Subject to fusion +-- +-- @since TODO +foldWhile :: Monad m => (a -> s -> Either e s) -> s -> C.ConduitT a o m (Either e s) +foldWhile f = loop + where + loop !s = C.await >>= maybe (pure $ Right s) go + where + go a = either (pure . Left $!) loop $ f a s +{-# INLINE foldWhile #-} +STREAMING(foldWhile) + + -- | 'concatMap' with an accumulator. -- -- Subject to fusion From 0b3128c8d5b079a3fb9ef304acb324b7174644ac Mon Sep 17 00:00:00 2001 From: ocramz Date: Sun, 22 Nov 2020 18:20:21 +0100 Subject: [PATCH 2/6] export foldWhile --- conduit/src/Data/Conduit/Combinators.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/conduit/src/Data/Conduit/Combinators.hs b/conduit/src/Data/Conduit/Combinators.hs index 2682f15e4..b00ade100 100644 --- a/conduit/src/Data/Conduit/Combinators.hs +++ b/conduit/src/Data/Conduit/Combinators.hs @@ -62,6 +62,7 @@ module Data.Conduit.Combinators , foldlE , foldMap , foldMapE + , foldWhile , all , allE , any From 3cf1f2a89d047215245506f0780b5da53d92f523 Mon Sep 17 00:00:00 2001 From: ocramz Date: Tue, 24 Nov 2020 14:27:40 +0100 Subject: [PATCH 3/6] version bump to 1.3.4 and hopefully fix STREAMING macro --- conduit/ChangeLog.md | 4 ++++ conduit/conduit.cabal | 2 +- conduit/src/Data/Conduit/Combinators.hs | 10 +++++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/conduit/ChangeLog.md b/conduit/ChangeLog.md index ed15cfc01..f72ef8a30 100644 --- a/conduit/ChangeLog.md +++ b/conduit/ChangeLog.md @@ -1,5 +1,9 @@ # ChangeLog for conduit +## 1.3.4 + +* Add `foldWhile` [#453](https://github.com/snoyberg/conduit/issues/453) [#456](https://github.com/snoyberg/conduit/pull/456). + ## 1.3.3 * Add `uncons`, `unconsM`, `unconsEither`, `unconsEitherM`. diff --git a/conduit/conduit.cabal b/conduit/conduit.cabal index 375d36f5b..9dfc12efc 100644 --- a/conduit/conduit.cabal +++ b/conduit/conduit.cabal @@ -1,5 +1,5 @@ Name: conduit -Version: 1.3.3 +Version: 1.3.4 Synopsis: Streaming data processing library. description: `conduit` is a solution to the streaming data problem, allowing for production, diff --git a/conduit/src/Data/Conduit/Combinators.hs b/conduit/src/Data/Conduit/Combinators.hs index b00ade100..c880b0665 100644 --- a/conduit/src/Data/Conduit/Combinators.hs +++ b/conduit/src/Data/Conduit/Combinators.hs @@ -1761,15 +1761,15 @@ STREAMING(mapAccumWhile, mapAccumWhileC, mapAccumWhileS, f s) -- -- Subject to fusion -- --- @since TODO -foldWhile :: Monad m => (a -> s -> Either e s) -> s -> C.ConduitT a o m (Either e s) -foldWhile f = loop +-- @since 1.3.4 +foldWhile, foldWhileC :: Monad m => (a -> s -> Either e s) -> s -> C.ConduitT a o m (Either e s) +foldWhileC f = loop where loop !s = C.await >>= maybe (pure $ Right s) go where go a = either (pure . Left $!) loop $ f a s -{-# INLINE foldWhile #-} -STREAMING(foldWhile) +{-# INLINE foldWhileC #-} +STREAMING(foldWhile, foldWhileC, foldWhileS, f s) -- | 'concatMap' with an accumulator. From 1e7735e098df74b02c82b3f5540384c56bea4591 Mon Sep 17 00:00:00 2001 From: ocramz Date: Tue, 24 Nov 2020 15:29:59 +0100 Subject: [PATCH 4/6] fix qualified imports --- conduit/src/Data/Conduit/Combinators.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conduit/src/Data/Conduit/Combinators.hs b/conduit/src/Data/Conduit/Combinators.hs index c880b0665..2323a01e5 100644 --- a/conduit/src/Data/Conduit/Combinators.hs +++ b/conduit/src/Data/Conduit/Combinators.hs @@ -1762,10 +1762,10 @@ STREAMING(mapAccumWhile, mapAccumWhileC, mapAccumWhileS, f s) -- Subject to fusion -- -- @since 1.3.4 -foldWhile, foldWhileC :: Monad m => (a -> s -> Either e s) -> s -> C.ConduitT a o m (Either e s) +foldWhile, foldWhileC :: Monad m => (a -> s -> Either e s) -> s -> ConduitT a o m (Either e s) foldWhileC f = loop where - loop !s = C.await >>= maybe (pure $ Right s) go + loop !s = await >>= maybe (pure $ Right s) go where go a = either (pure . Left $!) loop $ f a s {-# INLINE foldWhileC #-} From b94bec006f2fb3d3c6ee9f809da86671e75beb7a Mon Sep 17 00:00:00 2001 From: ocramz Date: Tue, 24 Nov 2020 16:11:20 +0100 Subject: [PATCH 5/6] lacks STREAMING --- conduit/src/Data/Conduit/Combinators.hs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/conduit/src/Data/Conduit/Combinators.hs b/conduit/src/Data/Conduit/Combinators.hs index 2323a01e5..1dbf79277 100644 --- a/conduit/src/Data/Conduit/Combinators.hs +++ b/conduit/src/Data/Conduit/Combinators.hs @@ -1762,14 +1762,13 @@ STREAMING(mapAccumWhile, mapAccumWhileC, mapAccumWhileS, f s) -- Subject to fusion -- -- @since 1.3.4 -foldWhile, foldWhileC :: Monad m => (a -> s -> Either e s) -> s -> ConduitT a o m (Either e s) -foldWhileC f = loop +foldWhile :: Monad m => (a -> s -> Either e s) -> s -> ConduitT a o m (Either e s) +foldWhile f = loop where - loop !s = await >>= maybe (pure $ Right s) go + loop !s = await >>= maybe (return $ Right s) go where - go a = either (pure . Left $!) loop $ f a s -{-# INLINE foldWhileC #-} -STREAMING(foldWhile, foldWhileC, foldWhileS, f s) + go a = either (return . Left $!) loop $ f a s +{-# INLINE foldWhile #-} -- | 'concatMap' with an accumulator. From cd3c7c8dd93936034f3315cdf59c0c34e49bda67 Mon Sep 17 00:00:00 2001 From: ocramz Date: Wed, 25 Nov 2020 08:23:27 +0100 Subject: [PATCH 6/6] remove fusion comment --- conduit/src/Data/Conduit/Combinators.hs | 2 -- 1 file changed, 2 deletions(-) diff --git a/conduit/src/Data/Conduit/Combinators.hs b/conduit/src/Data/Conduit/Combinators.hs index 1dbf79277..a3dab7c95 100644 --- a/conduit/src/Data/Conduit/Combinators.hs +++ b/conduit/src/Data/Conduit/Combinators.hs @@ -1759,8 +1759,6 @@ STREAMING(mapAccumWhile, mapAccumWhileC, mapAccumWhileS, f s) -- | Specialized version of 'mapAccumWhile' that does not provide values downstream. -- --- Subject to fusion --- -- @since 1.3.4 foldWhile :: Monad m => (a -> s -> Either e s) -> s -> ConduitT a o m (Either e s) foldWhile f = loop