I am trying my hand at a pipeline which uses delayed effect result values 
to process incoming values. For instance, if I set a delay of three steps, 
the result obtained in the first step will be used for processing the 
fourth incoming value, the fifth result will be used with the second input, 
and so forth. For now I managed to make it work by chunking result values 
with mapM. Below is a minimal example of the sort of wiring I aim for:

foo :: Pipe Int (Maybe Int, Int) IO () 
foo = do
    let delays = replicate 3 Nothing
        runWindow = lowerCodensity . mapM (\y -> lift $
            await >>= \x -> yield (y, x) >> return (Just x))
    iterateM_ runWindow delays
    where
    iterateM_ f x = f x >>= iterateM_ f

>>> runEffect $ each [1..6] >-> foo >-> P.print

(Nothing,1)
(Nothing,2)
(Nothing,3)
(Just 1,4)
(Just 2,5)
(Just 3,6)


This seems to do the job - effect sequencing and downsteaming are fine, and 
so is memory consumption (linear in the delay size seems hard to avoid). 
But is there a way more idiomatic than resorting to mapM?

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