Something of type Pipe (k,v) (k,v) m r would have to miss the last group of 
values, no? Or maybe I'm not following. If upstream is following a 
quasi-conduit strategy where await yields a Maybe and Nothing signals eof, 
you could write, say: 

    pipeFoldValues :: (Monad m, Eq k) => (v -> v -> v) -> Pipe (Maybe 
(k,v)) (k, v) m ()
    pipeFoldValues append  = go Nothing where

      go (Just (k,v)) = do 
        a <- await
        case a of 
          Nothing -> yield (k,v)  
          Just (k',v') | k == k' -> go (Just (k,append v v'))
          Just (k',v') -> do 
            yield (k,v) 
            go (Just (k',v'))
         
      go Nothing = do 
        a <- await
        go a


or maybe a pipe that maintains this rule is better: 

    pipeFoldValues :: (Monad m, Eq k) => (v -> v -> v) -> Pipe (Maybe 
(k,v)) (Maybe (k, v)) m r
    pipeFoldValues append  = go Nothing where

      go (Just (k,v)) = do 
        a <- await
        case a of 
          Nothing -> yield (Just (k,v)) >> forever (yield Nothing)
          Just (k',v') | k == k' -> go (Just (k,append v v'))
          Just (k',v') -> do 
            yield (Just (k,v)) 
            go (Just (k',v'))
 
      go Nothing = do 
        a <- await
        go a
 

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