pipes-transduce-0.4.4.0: Interfacing pipes with foldl folds.

Safe HaskellNone
LanguageHaskell98

Pipes.Transduce.Text

Contents

Synopsis

Text folds

intoLazyText :: Fold1 Text e Text Source #

Collect strict Texts into a lazy Text.

>>> fold1  intoLazyText (mapM_ yield ["aa","bb","cc"])
("aabbcc",())

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!

type Line = Text Source #

Whole lines are represented as lazy Text values.

asFoldedLines :: Fold1 Line e r -> Fold1 Text e r Source #

Transforms a Fold1 that accepts whole lines into a Fold1 that accepts and undivided text stream.

>>> fold1 (asFoldedLines (withFold L.list)) (mapM_ yield ["aa","aa\nbb","bb"])
(["aaaa","bbbb"],())

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

decoder Source #

Plug decoding functions from pipes-text here.

The first undecodable bytes will be the error value.

decoderx Source #

Plug decoding functions from pipes-text here.

BEWARE! This Transducer may throw DecodeError. BEWARE!

utf8 Source #

The first undecodable bytes will be the error value.

>>> fold1Fallibly (transduce1 utf8 intoLazyText) (mapM_ yield ["aa"])
Right ("aa",())

utf8x Source #

>>> fold1  (transduce1 utf8x intoLazyText) (mapM_ yield ["aa"])
("aa",())

BEWARE! This Transducer may throw DecodeError. BEWARE!

Splitting

lines Source #

Split into lines, preserving newlines.

>>> fold1 (transduce1 (concats . groups (\p -> yield "x" *> p) . lines $ utf8x) intoLazyText) (mapM_ yield ["aa\n","bb"])
("xaa\nxbb\n",())

lines_ Source #

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"],())