Skip to content

Commit

Permalink
Merge pull request #456 from ocramz/master
Browse files Browse the repository at this point in the history
add foldWhile
  • Loading branch information
snoyberg authored Nov 25, 2020
2 parents 2f9e868 + cd3c7c8 commit 0bf72ae
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions conduit/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion conduit/conduit.cabal
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
14 changes: 14 additions & 0 deletions conduit/src/Data/Conduit/Combinators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ module Data.Conduit.Combinators
, foldlE
, foldMap
, foldMapE
, foldWhile
, all
, allE
, any
Expand Down Expand Up @@ -1755,6 +1756,19 @@ mapAccumWhileC f =
{-# INLINE mapAccumWhileC #-}
STREAMING(mapAccumWhile, mapAccumWhileC, mapAccumWhileS, f s)


-- | Specialized version of 'mapAccumWhile' that does not provide values downstream.
--
-- @since 1.3.4
foldWhile :: Monad m => (a -> s -> Either e s) -> s -> ConduitT a o m (Either e s)
foldWhile f = loop
where
loop !s = await >>= maybe (return $ Right s) go
where
go a = either (return . Left $!) loop $ f a s
{-# INLINE foldWhile #-}


-- | 'concatMap' with an accumulator.
--
-- Subject to fusion
Expand Down

0 comments on commit 0bf72ae

Please sign in to comment.