Created
March 31, 2013 09:34
-
-
Save danidiaz/5280121 to your computer and use it in GitHub Desktop.
Unstandard way of zipping conduits.
This file contains 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.Functor.Identity | |
import Control.Applicative | |
import Control.Monad | |
import Control.Monad.Trans | |
import Control.Monad.Trans.Maybe | |
-- From the monad-loops package | |
import Control.Monad.Loops | |
import Data.Void | |
import Data.Conduit | |
import Data.Conduit.List | |
zippedSource :: Monad m => Sink a (ConduitM b Void (ConduitM () (a,b) m)) () | |
zippedSource = let mpair = (,) <$> MaybeT await <*> MaybeT (lift await) | |
in whileJust_ (runMaybeT mpair) $ lift . lift . yield | |
-- This has a scary type | |
zip' s1 s2 = s2 $$ (s1 $$ zippedSource) | |
resultList :: [(Int,Char)] | |
resultList = let zipped = zip' (sourceList [1, 2, 3]) (sourceList ['a', 'b', 'c']) | |
in runIdentity (zipped $$ consume) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment