altering lines to split on a two-character delimiter

17 views
Skip to first unread message

Erik Rantapaa

unread,
Jun 5, 2016, 2:34:08 AM6/5/16
to Haskell Pipes
I'm trying my hand at writing a Producer "transformer" similar to `Pipes.ByteString.lines` which will split a ByteString stream into lines ending in the string `"xy"`.

You can view my latest attempt at:

http://lpaste.net/165424

My functions corresponding to `line`, `_lines` and `lines` are `splitXY`, `_splitXY`, and  `splitXYs`.

It seems to work - try running `main1` and `main2`. The questions I have are:

1. Any issues with the code? (One problem I just spotted while writing this post is that if the input stream ends in `"xy"` an extra empty string is yielded at the end.)

2. Is there a library function which does the work of `loop1` -- i.e. traversing down a `Producer ... (Producer ...)` chain?

3. `splitXYs` was written to be analogous to `lines`, but GHC complains when I try type it the same way. ???

4. This was just an exercise in understanding how `lines` worked. What would be the recommended way to do this in the pipes ecosystem?

Thanks,
Erik

Reply all
Reply to author
Forward
0 new messages