Created
September 14, 2013 17:48
-
-
Save xkikeg/6564038 to your computer and use it in GitHub Desktop.
特定の値を読み込むまでのConduit ref: http://qiita.com/liquidamber/items/22e3d791c3396b3ab13d
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
{-# LANGUAGE OverloadedStrings #-} | |
import Data.Conduit | |
import qualified Data.Conduit.Binary as CB | |
import qualified Data.Conduit.List as CL | |
takeWhile' :: Monad m => (a -> Bool) -> Conduit a m a | |
takeWhile' f = do | |
mx <- await | |
case mx of | |
Nothing -> return () | |
Just x | |
| f x -> yield x >> takeWhile' f | |
| otherwise -> return () | |
main = do | |
ss <- | |
runResourceT $ | |
CB.sourceFile "hogehoge" | |
$= CB.lines | |
$= takeWhile' (/= "END") | |
$$ CL.consume | |
print ss |
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
waiwai | |
weiwei | |
yahoo | |
END | |
hoge | |
hoge |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment