Created
December 22, 2011 20:50
-
-
Save aristidb/1511804 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Data.Conduit | |
| import Control.Monad.Trans.Resource | |
| import Control.Monad | |
| joinSource :: Resource m => Source m (Source m a) -> Source m a | |
| joinSource s = Source $ do | |
| ps <- genSource s | |
| innerSources <- newRef [] | |
| let pull = do xs <- readRef innerSources | |
| case xs of | |
| (x:xss) -> do SourceResult st vs <- sourcePull x | |
| case st of | |
| StreamClosed -> writeRef innerSources xss | |
| StreamOpen -> return () | |
| return $ SourceResult StreamOpen vs | |
| [] -> do SourceResult st xs' <- sourcePull ps | |
| writeRef innerSources =<< mapM genSource xs' | |
| return $ SourceResult st [] | |
| close = do mapM_ sourceClose =<< readRef innerSources | |
| sourceClose ps | |
| return $ PureSource { | |
| sourcePull = pull | |
| , sourceClose = close | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment