Skip to content

Instantly share code, notes, and snippets.

@danidiaz
Created March 31, 2013 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danidiaz/5280121 to your computer and use it in GitHub Desktop.
Save danidiaz/5280121 to your computer and use it in GitHub Desktop.
Unstandard way of zipping conduits.
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