Created
November 6, 2012 18:10
-
-
Save qrilka/4026464 to your computer and use it in GitHub Desktop.
ResumableSource example
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 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