diff options
author | michaelt <what_is_it_to_do_anything@yahoo.com> | 2013-10-30 16:07:17 -0400 |
---|---|---|
committer | michaelt <what_is_it_to_do_anything@yahoo.com> | 2013-10-30 16:07:17 -0400 |
commit | acc6868f63bdbede411874f4cfdbbb2d4bfa41da (patch) | |
tree | f93cb3ca240156a7612b224e5462bb18bad71648 | |
parent | 1d2434b57d4f810867794e68432468b0a200aab1 (diff) | |
download | text-pipes-acc6868f63bdbede411874f4cfdbbb2d4bfa41da.tar.gz text-pipes-acc6868f63bdbede411874f4cfdbbb2d4bfa41da.tar.zst text-pipes-acc6868f63bdbede411874f4cfdbbb2d4bfa41da.zip |
words
-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 |