I've found a place where I can grab a Producer, so it all seems to work, 
but I am still curious why pipes-group only works on Producers and not 
Pipes.

cheers
Mark

On Wednesday, July 2, 2014 3:02:59 PM UTC+7, Mark Wotton wrote:
>
> is there a way to do this with pipes rather than producers? I need to 
> feed this with input from somewhere else... 
>
> cheers 
> mark 
>
> On Wed, Jul 2, 2014 at 12:53 PM, Gabriel Gonzalez <[email protected]> 
> wrote: 
> > 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]. 
> > To post to this group, send email to [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]. 
>
>
>
> -- 
> A UNIX signature isn't a return address, it's the ASCII equivalent of a 
> black velvet clown painting. It's a rectangle of carets surrounding a 
> quote from a literary giant of weeniedom like Heinlein or Dr. Who. 
>         -- Chris Maeda 
>

-- 
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].

Reply via email to