The basic flow is:
* Split the `Producer` into sub-`Producer`s of up to N elements each,
using `Pipes.Group.chunksOf`
* Fold each sub-`Producer` into a list or vector using `Pipes.Group.folds`
Here's the code:
import Control.Foldl (purely, list)
import Lens.Family (view)
import Pipes.Group (Producer, chunksOf, folds)
example :: Monad m => Int -> Producer a m r -> Producer [a] m r
example n = purely folds list . view (chunksOf n)
I know that's hard to discover because it spans three separate
libraries. I'm working on a cookbook post to teach tricks like these.
In this case, the `Pipes.Group.Tutorial` explains how `chunksOf` works,
while the `foldl` library explains how `purely` works.
If you're wondering why `chunksOf` is a lens instead of a function, it's
so that you can do things like this:
over (chunksOf 3) (<* yield 0) (each [1..10]) == each [1, 2, 3, 0,
4, 5, 6, 0, 7, 8, 9, 0, 10, 0]
On 7/1/14, 9:51 PM, Mark Wotton wrote:
Apologies for what's probably a fairly newbish sort of question: I'm
trying to write an efficient pipe for direct-sqlite.
While I could run each insert in a separate transaction, this would
kill my performance. Thus, I'm trying to find a way of saying "give me
everything you have available right now, up to a maximum of N writes".
Nick Partridge pointed me to pipes-group, and chunksOf in particular
looks interesting but I'm having some trouble understanding how to use
it. Could anyone give me a pointer?
(In this case, it is actually a pipe rather than just a consumer,
because I need to notify another part of the system that the write has
finished.)
cheers
Mark
--
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 [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
--
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 [email protected].
To post to this group, send email to [email protected].