This is really good stuff.  Nice catch on missing the re-yielding of \n\n.  
I'm sure that might have already bitten me as I experimented.  I should 
have just used the lens iso function to create my lens instead of trying to 
do it manually.

>Note that as it stands this silently accumulates everything before the 
double newline.

I was hoping that actually would not be the case, since in my function I'm 
immediately yielding everything I can before looping.  If it is 
accumulating data as it runs, that's exactly what I was hoping to avoid by 
writing this.

Your musings with groupsBy and PG.folds were definitely along the lines of 
what I was looking for.  Reading what you wrote, I see why it is such a 
hard problem.  You basically have to split the bytestring up into chunks 
that can be consumed by other combinators, but it is hard because all of 
the existing pipes functions for bytestrings assume breaking or spanning on 
a single character, rather than several of them in a row.

split :: (Monad m, Eq a) => a -> Lens' (Producer a m r) (FreeT (Producer a 
m) m r)
I guess what I we really need is exactly what you specified, but it won't 
work for bytestrings in the general case because the delimiter may not be 
in its own chunk.

There would have to be bytestring / text specific combinators in 
pipes-bytestring and pipes-text like
split :: (Monad m) => ByteString -> Lens' (Producer BytesString m r) (FreeT 
(Producer ByteString m) m r)
that does the splitting and recombining via an argument.

I only have breakOnText :: Monad m => Text -> Lens' (Producer Text m a) 
(Producer Text m (Producer Text m a)), and so it is not quite good enough 
to submit a pull request for.


On Thursday, August 18, 2016 at 8:48:15 PM UTC-4, Michael Thompson wrote:
>
> One more correction: it seems the type should be  
>
>    split :: (Monad m, Eq a) => a -> Lens' (Producer a m r) (FreeT 
> (Producer a m) m r)
>
> since the lens should reinsert the thing we split on. If we use a 
> predicate, we don't know what it was.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Haskell Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to haskell-pipes+unsubscr...@googlegroups.com.
To post to this group, send email to haskell-pipes@googlegroups.com.

Reply via email to