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

Safe HaskellNone
LanguageHaskell98

Pipes.Transduce.Text

Contents

Synopsis

Collecting input

intoLazyText :: Fold1 Text e Text Source

Collect strict Texts into a lazy Text.

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

Splitting

lines Source

Arguments

:: Transducer Continuous a e Text 
-> Transducer Delimited a e Text 

Split into lines, preserving newlines.

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

lines_ Source

Arguments

:: Transducer Continuous a e Text 
-> Transducer Delimited a e Text 

Split into lines, eliding newlines.

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

Grouping

foldedLines :: Transducer Continuous Text e Text Source

Split the stream into lines, collect them into lazy Text values, and pass them downstream.

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

eachLine :: (Text -> 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.

>>> PT.fold1Fallibly (eachLine $ \l -> pure $ if TL.head l == 'b' then (Left l) else (Right ())) (mapM_ yield ["aa","\nbb"])
Left "bb"

Decoding

decoder Source

Arguments

:: (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.

decoderx Source

Arguments

:: (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!

utf8 Source

The first undecodable bytes will be the error value.

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

utf8x Source

Arguments

:: Transducer Continuous ByteString e Text 
>>> PT.fold1  (transduce1 utf8x intoLazyText) (mapM_ yield ["aa"])
("aa",())

BEWARE! This Transducer may throw DecodeError. BEWARE!