From: Gabriel Gonzalez Date: Fri, 7 Feb 2014 15:08:47 +0000 (+0700) Subject: Fixed `scan` X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=11645cdce20ff843caf8b53f82f2c32050fdd1fd;p=github%2Ffretlink%2Ftext-pipes.git 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. --- 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 #-}