iteratee "folding" version of ilift

Alex Lang lang at
Tue Nov 8 15:12:36 GMT 2011


I propose a version of ilift which threads through an accumulator to
consecutive invocations of the argument function.

ifold :: (Monad m, Monad n) => (forall r. m r -> acc -> n (r, acc))
      -> acc -> Iteratee s m a -> Iteratee s n (a, acc)
ifold f acc i = Iteratee $ \ od oc -> do
  (r, acc') <- flip f acc $
    runIter i (curry $ return . Left) (curry $ return . Right)
  either (uncurry (od . flip (,) acc'))
         (uncurry (oc . (ifold f acc' .))) r

I don't think ifold is a very good name, but I could not think of a
better one. I think it is a "fold" in the same sense that mapIteratee
is a "map". Thinking about it, I don't think ilift is a very good name
either, but I have no better suggestion.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ifold.patch
Type: text/x-patch
Size: 8811 bytes
Desc: not available
URL: <>

More information about the Iteratee mailing list