Skip to content
This repository has been archived by the owner on Nov 19, 2023. It is now read-only.

Commit

Permalink
Adapt feed to simplified handlers.
Browse files Browse the repository at this point in the history
  • Loading branch information
pcapriotti committed Feb 29, 2012
1 parent ef56956 commit 1a07964
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions pipes-extra/Control/Pipe/Combinators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module Control.Pipe.Combinators (

import Control.Applicative
import Control.Monad
import Control.Monad.Free
import Control.Pipe
import Data.Maybe
import Prelude hiding (until, take, drop, concatMap, filter, takeWhile, dropWhile)
Expand Down Expand Up @@ -120,13 +119,11 @@ feed :: Monad m => a -> Pipe a b m r -> Pipe a b m r
-- feed x p = (yield x >> idP) >+> p
-- but this version is more efficient
feed _ (Pure r) = return r
feed a (Free c) = go c >>= \(done, p) ->
if done then p else feed a p
feed _ (Throw e) = throw e
feed a (Free c h) = case go a c of
(False, p) -> p >>= feed a
(True, p) -> join p
where
go (Await k) = return (True, k a)
go (Yield y c) = yield y >> return (False, c)
go (M m s) = lift_ s m >>= continue
go (Catch s h) = catchP (go s) (h >=> return . continue)
go (Throw e) = throw e

continue p = return (False, p)
go a (Await k) = (True, return $ k a)
go _ (Yield y c) = (False, yield y >> return c)
go _ (M m s) = (False, lift_ s m)
2 changes: 1 addition & 1 deletion pipes-zlib/Control/Pipe/Zlib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ callback pop = go id where
Just y -> go (xs . (y:))

whileAwait :: (Show a, MonadIO m) => (a -> Pipe a b m r) -> Pipe a b m ()
whileAwait f = catch_ (forever $ await >>= f)
whileAwait f = catch (forever $ await >>= f)
(\(_ :: BrokenUpstreamPipe) -> return ())

0 comments on commit 1a07964

Please sign in to comment.