Skip to content

Instantly share code, notes, and snippets.

@xkikeg
Created September 14, 2013 17:48
Show Gist options
  • Save xkikeg/6564038 to your computer and use it in GitHub Desktop.
Save xkikeg/6564038 to your computer and use it in GitHub Desktop.
特定の値を読み込むまでのConduit ref: http://qiita.com/liquidamber/items/22e3d791c3396b3ab13d
{-# 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
waiwai
weiwei
yahoo
END
hoge
hoge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment