diff options
author | Gabriel Gonzalez <Gabriel439@gmail.com> | 2014-02-07 22:08:47 +0700 |
---|---|---|
committer | Gabriel Gonzalez <Gabriel439@gmail.com> | 2014-02-07 22:09:38 +0700 |
commit | 11645cdce20ff843caf8b53f82f2c32050fdd1fd (patch) | |
tree | 70ad8ff9afa81b17671bbe1ea4abce32aed06be4 /Pipes | |
parent | ca7b86be9116503f9ecc176b45bb3c695dc94b73 (diff) | |
download | text-pipes-11645cdce20ff843caf8b53f82f2c32050fdd1fd.tar.gz text-pipes-11645cdce20ff843caf8b53f82f2c32050fdd1fd.tar.zst text-pipes-11645cdce20ff843caf8b53f82f2c32050fdd1fd.zip |
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.
Diffstat (limited to 'Pipes')
-rw-r--r-- | Pipes/Text.hs | 6 |
1 files 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) | |||
485 | scan | 485 | scan |
486 | :: (Monad m) | 486 | :: (Monad m) |
487 | => (Char -> Char -> Char) -> Char -> Pipe Text Text m r | 487 | => (Char -> Char -> Char) -> Char -> Pipe Text Text m r |
488 | scan step begin = go begin | 488 | scan step begin = do |
489 | yield (T.singleton begin) | ||
490 | go begin | ||
489 | where | 491 | where |
490 | go c = do | 492 | go c = do |
491 | txt <- await | 493 | txt <- await |
492 | let txt' = T.scanl step c txt | 494 | let txt' = T.scanl step c txt |
493 | c' = T.last txt' | 495 | c' = T.last txt' |
494 | yield txt' | 496 | yield (T.tail txt') |
495 | go c' | 497 | go c' |
496 | {-# INLINABLE scan #-} | 498 | {-# INLINABLE scan #-} |
497 | 499 | ||