From 11645cdce20ff843caf8b53f82f2c32050fdd1fd Mon Sep 17 00:00:00 2001 From: Gabriel Gonzalez Date: Fri, 7 Feb 2014 22:08:47 +0700 Subject: [PATCH] Fixed `scan` The first `Char` of each output chunk is redundant (since it would have been emitted by the previous chunk). This removes the duplicate `Char`s. Note that this bug was present in `pipes-bytestring` as well, and I fixed it there, too. --- Pipes/Text.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Pipes/Text.hs b/Pipes/Text.hs index eb72be2..4b2d2b0 100644 --- a/Pipes/Text.hs +++ b/Pipes/Text.hs @@ -485,13 +485,15 @@ filter predicate = P.map (T.filter predicate) scan :: (Monad m) => (Char -> Char -> Char) -> Char -> Pipe Text Text m r -scan step begin = go begin +scan step begin = do + yield (T.singleton begin) + go begin where go c = do txt <- await let txt' = T.scanl step c txt c' = T.last txt' - yield txt' + yield (T.tail txt') go c' {-# INLINABLE scan #-} -- 2.41.0