diff options
-rw-r--r-- | Pipes/Text.hs | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/Pipes/Text.hs b/Pipes/Text.hs index a3e85b2..1092491 100644 --- a/Pipes/Text.hs +++ b/Pipes/Text.hs | |||
@@ -143,7 +143,7 @@ module Pipes.Text ( | |||
143 | 143 | ||
144 | import Control.Exception (throwIO, try) | 144 | import Control.Exception (throwIO, try) |
145 | import Control.Monad (liftM, unless) | 145 | import Control.Monad (liftM, unless) |
146 | import Control.Monad.Trans.State.Strict (StateT) | 146 | import Control.Monad.Trans.State.Strict (StateT(..)) |
147 | import qualified Data.Text as T | 147 | import qualified Data.Text as T |
148 | import qualified Data.Text.IO as T | 148 | import qualified Data.Text.IO as T |
149 | import qualified Data.Text.Encoding as TE | 149 | import qualified Data.Text.Encoding as TE |
@@ -755,18 +755,22 @@ words | |||
755 | :: (Monad m) => Producer Text m r -> FreeT (Producer Text m) m r | 755 | :: (Monad m) => Producer Text m r -> FreeT (Producer Text m) m r |
756 | words p0 = removeEmpty (splitWith isSpace p0) | 756 | words p0 = removeEmpty (splitWith isSpace p0) |
757 | where | 757 | where |
758 | removeEmpty f = PP.FreeT $ do | 758 | removeEmpty f = PP.FreeT $ do |
759 | x <- PP.runFreeT f | 759 | x <- PP.runFreeT f |
760 | case x of | 760 | case x of |
761 | PP.Pure r -> return (PP.Pure r) | 761 | PP.Pure r -> return (PP.Pure r) |
762 | PP.Free p -> do | 762 | PP.Free p -> loop p |
763 | y <- next p | 763 | loop p = do |
764 | case y of | 764 | y <- next p |
765 | Left f' -> PP.runFreeT (removeEmpty f') | 765 | case y of |
766 | Right (bs, p') -> return $ PP.Free $ do | 766 | Left f' -> PP.runFreeT (removeEmpty f') |
767 | yield bs | 767 | Right (txt, p') -> |
768 | f' <- p' | 768 | if T.null txt |
769 | return (removeEmpty f') | 769 | then loop p' |
770 | else return $ PP.Free $ do | ||
771 | yield txt | ||
772 | f' <- p' | ||
773 | return (removeEmpty f') | ||
770 | {-# INLINABLE words #-} | 774 | {-# INLINABLE words #-} |
771 | 775 | ||
772 | -- | Intersperse a 'Char' in between the characters of the text stream | 776 | -- | Intersperse a 'Char' in between the characters of the text stream |