aboutsummaryrefslogtreecommitdiffhomepage
path: root/Pipes
diff options
context:
space:
mode:
Diffstat (limited to 'Pipes')
-rw-r--r--Pipes/Text.hs23
1 files changed, 21 insertions, 2 deletions
diff --git a/Pipes/Text.hs b/Pipes/Text.hs
index 7722f7f..0f2e31d 100644
--- a/Pipes/Text.hs
+++ b/Pipes/Text.hs
@@ -128,8 +128,16 @@ import Prelude hiding (
128 words, 128 words,
129 writeFile ) 129 writeFile )
130 130
131 131-- $setup
132-- | Convert a lazy 'TL.Text' into a 'Producer' of strict 'Text's 132-- >>> :set -XOverloadedStrings
133-- >>> import Data.Text (Text)
134-- >>> import qualified Data.Text as T
135-- >>> import qualified Data.Text.Lazy.IO as TL
136-- >>> import Data.Char
137
138-- | Convert a lazy 'TL.Text' into a 'Producer' of strict 'Text's. Producers in
139-- IO can be found in 'Pipes.Text.IO' or in pipes-bytestring, employed with the
140-- decoding lenses in 'Pipes.Text.Encoding'
133fromLazy :: (Monad m) => TL.Text -> Producer' Text m () 141fromLazy :: (Monad m) => TL.Text -> Producer' Text m ()
134fromLazy = TL.foldrChunks (\e a -> yield e >> a) (return ()) 142fromLazy = TL.foldrChunks (\e a -> yield e >> a) (return ())
135{-# INLINE fromLazy #-} 143{-# INLINE fromLazy #-}
@@ -138,11 +146,17 @@ fromLazy = TL.foldrChunks (\e a -> yield e >> a) (return ())
138a ^. lens = getConstant (lens Constant a) 146a ^. lens = getConstant (lens Constant a)
139 147
140-- | Apply a transformation to each 'Char' in the stream 148-- | Apply a transformation to each 'Char' in the stream
149
150-- >>> let margaret = ["Margaret, are you grieving\nOver Golde","ngrove unleaving?":: Text]
151-- >>> TL.putStrLn $ toLazy $ each margaret >-> map Data.Char.toUpper
152-- MARGARET, ARE YOU GRIEVING
153-- OVER GOLDENGROVE UNLEAVING?
141map :: (Monad m) => (Char -> Char) -> Pipe Text Text m r 154map :: (Monad m) => (Char -> Char) -> Pipe Text Text m r
142map f = P.map (T.map f) 155map f = P.map (T.map f)
143{-# INLINABLE map #-} 156{-# INLINABLE map #-}
144 157
145-- | Map a function over the characters of a text stream and concatenate the results 158-- | Map a function over the characters of a text stream and concatenate the results
159
146concatMap 160concatMap
147 :: (Monad m) => (Char -> Text) -> Pipe Text Text m r 161 :: (Monad m) => (Char -> Text) -> Pipe Text Text m r
148concatMap f = P.map (T.concatMap f) 162concatMap f = P.map (T.concatMap f)
@@ -184,6 +198,11 @@ filter predicate = P.map (T.filter predicate)
184{-# INLINABLE filter #-} 198{-# INLINABLE filter #-}
185 199
186-- | Strict left scan over the characters 200-- | Strict left scan over the characters
201-- >>> let margaret = ["Margaret, are you grieving\nOver Golde","ngrove unleaving?":: Text]
202-- >>> let title_caser a x = case a of ' ' -> Data.Char.toUpper x; _ -> x
203-- >>> toLazy $ each margaret >-> scan title_caser ' '
204-- " Margaret, Are You Grieving\nOver Goldengrove Unleaving?"
205
187scan 206scan
188 :: (Monad m) 207 :: (Monad m)
189 => (Char -> Char -> Char) -> Char -> Pipe Text Text m r 208 => (Char -> Char -> Char) -> Char -> Pipe Text Text m r