[Haskell-cafe] file splitter with enumerator package

Yves Parès limestrael at gmail.com
Mon Jul 25 12:26:23 CEST 2011


Okay, so there, the chunks (xs) will be lines of Text, and not just random
blocks.
Isn't there a primitive like printChunks in the enumerator library, or are
we forced to handle Chunks and EOF by hand?

2011/7/25 David McBride <dmcbride at neondsl.com>

> blah = do
>  fp <- openFile "file" ReadMode
>  run_ $ (ET.enumHandle fp $= ET.lines) $$ printChunks True
>
> printChunks is super duper simple:
>
> printChunks printEmpty = continue loop where
>        loop (Chunks xs) = do
>                let hide = null xs && not printEmpty
>                CM.unless hide (liftIO (print xs))
>                continue loop
>
>        loop EOF = do
>                liftIO (putStrLn "EOF")
>                yield () EOF
>
> Just replace print with whatever IO action you wanted to perform.
>
> On Mon, Jul 25, 2011 at 4:31 AM, Yves Parès <limestrael at gmail.com> wrote:
> > Sorry, I'm only beginning to understand iteratees, but then how do you
> > access each line of text output by the enumeratee "lines" within an
> > iteratee?
> >
> > 2011/7/24 Felipe Almeida Lessa <felipe.lessa at gmail.com>
> >>
> >> On Sun, Jul 24, 2011 at 12:28 PM, Yves Parès <limestrael at gmail.com>
> wrote:
> >> > If you used Data.Enumerator.Text, you would maybe benefit the "lines"
> >> > function:
> >> >
> >> > lines :: Monad m => Enumeratee Text Text m b
> >>
> >> It gets arbitrary blocks of text and outputs lines of text.
> >>
> >> > But there is something I don't get with that signature:
> >> > why isn't it:
> >> > lines :: Monad m => Enumeratee Text [Text] m b
> >> > ??
> >>
> >> Lists of lines of text?
> >>
> >> Cheers, =)
> >>
> >> --
> >> Felipe.
> >
> >
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110725/fe567eeb/attachment.htm>


More information about the Haskell-Cafe mailing list