Skip to content

Instantly share code, notes, and snippets.

@qrilka
Created November 6, 2012 18:10
Show Gist options
  • Save qrilka/4026464 to your computer and use it in GitHub Desktop.
Save qrilka/4026464 to your computer and use it in GitHub Desktop.
ResumableSource example
import Control.Monad.IO.Class
import Data.Conduit
import Data.Conduit.Binary as B
import Data.Conduit.List as L
import Data.Char
import Data.Word
{-
% cat input.txt
upload
1
hello
-}
nl :: Word8
nl = fromIntegral (ord '\n')
main = do
runResourceT $ do
let s = sourceFile "input.txt" -- $= B.lines
(next, head) <- s $$+ (B.takeWhile (/= nl) >+> L.consume) -- (B.lines >+> L.take 1)
liftIO $ print head
rest <- next $$+- L.consume
liftIO $ print rest
{-
-- OUTPUT:
["upload"]
["\n1\nhello\n"]
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment