Safe Haskell | None |
---|---|
Language | Haskell98 |
- intoLazyText :: Fold1 Text e Text
- asUtf8 :: (ByteString -> e) -> Fold1 Text e r -> Fold1 ByteString e r
- asUtf8x :: Fold1 Text e r -> Fold1 ByteString e r
- bothAsUtf8x :: Fold2 Text Text e r -> Fold2 ByteString ByteString e r
- type Line = Text
- asFoldedLines :: Fold1 Line e r -> Fold1 Text e r
- eachLine :: (Line -> IO (Either e ())) -> Fold1 Text e ()
- combinedLines :: Fold1 Text e r -> Fold2 Text Text e r
- combinedLinesPrefixing :: Text -> Text -> Fold1 Text e r -> Fold2 Text Text e r
- decoder :: (forall r. Producer ByteString IO r -> Producer Text IO (Producer ByteString IO r)) -> Transducer Continuous ByteString ByteString Text
- decoderx :: (forall r. Producer ByteString IO r -> Producer Text IO (Producer ByteString IO r)) -> Transducer Continuous ByteString e Text
- utf8 :: Transducer Continuous ByteString ByteString Text
- utf8x :: Transducer Continuous ByteString e Text
- lines :: Transducer Continuous a e Text -> Transducer Delimited a e Text
- lines_ :: Transducer Continuous a e Text -> Transducer Delimited a e Text
- foldedLines :: Transducer Continuous Text e Line
Text folds
asUtf8 :: (ByteString -> e) -> Fold1 Text e r -> Fold1 ByteString e r Source #
Turns a fold that accepts Text
into a fold that accepts UTF8-encoded
ByteString
.
It also takes a function that maps undecoded leftovers to a more general error type.
>>>
fold1Fallibly (asUtf8 id intoLazyText) (mapM_ yield ["aa"])
Right ("aa",())
asUtf8x :: Fold1 Text e r -> Fold1 ByteString e r Source #
Like asUtf8
, but throws exceptions in case of decoding errors.
>>>
fold1 (asUtf8x intoLazyText) (mapM_ yield ["aa"])
("aa",())
BEWARE!
This Transducer
may throw DecodeError
.
BEWARE!
bothAsUtf8x :: Fold2 Text Text e r -> Fold2 ByteString ByteString e r Source #
>>>
fold2 (bothAsUtf8x (combinedLines intoLazyText)) (mapM_ yield ["aa"]) (mapM_ yield ["aa"])
("aa\naa\n",(),())
BEWARE!
This Transducer
may throw DecodeError
.
BEWARE!
eachLine :: (Line -> IO (Either e ())) -> Fold1 Text e () Source #
Split the stream into lines, collect them into lazy Text
values, and
apply an effectul function to each line.
>>>
fold1Fallibly (eachLine $ \l -> pure $ if TL.head l == 'b' then (Left l) else (Right ())) (mapM_ yield ["aa","\nbb"])
Left "bb"
combinedLines :: Fold1 Text e r -> Fold2 Text Text e r Source #
Process two streams of text, combined as a single text stream.
The streams are combined line by line, but the resulting stream is undivided.
>>>
fold2 (combinedLines intoLazyText) (mapM_ yield ["aa"]) (mapM_ yield ["aa"])
("aa\naa\n",(),())
combinedLinesPrefixing :: Text -> Text -> Fold1 Text e r -> Fold2 Text Text e r Source #
Like combinedLines
, but adding different prefixes to lines from stdout
and stderr.
>>>
fold2 (combinedLinesPrefixing "-" "-" intoLazyText) (mapM_ yield ["aa"]) (mapM_ yield ["aa"])
("-aa\n-aa\n",(),())
Text transducers
Decoding
:: (forall r. Producer ByteString IO r -> Producer Text IO (Producer ByteString IO r)) | |
-> Transducer Continuous ByteString ByteString Text |
Plug decoding functions from pipes-text
here.
The first undecodable bytes will be the error value.
:: (forall r. Producer ByteString IO r -> Producer Text IO (Producer ByteString IO r)) | |
-> Transducer Continuous ByteString e Text |
Plug decoding functions from pipes-text
here.
BEWARE!
This Transducer
may throw DecodeError
.
BEWARE!
The first undecodable bytes will be the error value.
>>>
fold1Fallibly (transduce1 utf8 intoLazyText) (mapM_ yield ["aa"])
Right ("aa",())
>>>
fold1 (transduce1 utf8x intoLazyText) (mapM_ yield ["aa"])
("aa",())
BEWARE!
This Transducer
may throw DecodeError
.
BEWARE!
Splitting
:: Transducer Continuous a e Text | |
-> Transducer Delimited a e Text |
Split into lines, preserving newlines.
>>>
fold1 (transduce1 (concats . groups (\p -> yield "x" *> p) . lines $ utf8x) intoLazyText) (mapM_ yield ["aa\n","bb"])
("xaa\nxbb\n",())
:: Transducer Continuous a e Text | |
-> Transducer Delimited a e Text |
Split into lines, eliding newlines.
>>>
fold1 (transduce1 (concats . groups (\p -> yield "x" *> p) . lines_ $ utf8x) intoLazyText) (mapM_ yield ["aa\n","bb"])
("xaaxbb",())
foldedLines :: Transducer Continuous Text e Line Source #
Split the stream into lines, collect them into lazy Text
values, and pass
them downstream.
>>>
fold1 (transduce1 foldedLines (withFold L.list)) (mapM_ yield ["aa","aa\nbb","bb"])
(["aaaa","bbbb"],())