stringfmt
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Fmt.Text.Lazy

Description

Lazy Text as Mu (Cons StrictText).

Lazy Text is internally a linked list of strict chunks:

data Text = Empty | Chunk !StrictText Text

This is exactly Fix (Cons StrictText). This module provides conversions and operations that let you apply the full recursion scheme and streaming metamorphism infrastructure to lazy Text.

Synopsis

Conversion

toChunks :: Text -> Mu (Cons Text) Source #

View a lazy Text as Mu (Cons Text).

Each Cons layer holds one strict chunk.

O(n) — rebuilds the spine as a Church-encoded list.

fromChunks :: Mu (Cons Text) -> Text Source #

Reassemble a Mu (Cons Text) into a lazy Text.

O(n) — folds the Church-encoded list back into chunks.

toNuChunks :: Text -> Nu (Cons Text) Source #

View a lazy Text as Nu (Cons Text) for lazy streaming. O(1) construction — the Text itself is the seed.

Folding

foldChunks :: Algebra (Cons Text) a -> Text -> a Source #

Fold a lazy Text chunk by chunk.

foldChunks alg = fold alg . toChunks

Unfolding

unfoldChunks :: Coalgebra (Cons Text) a -> a -> Text Source #

Build a lazy Text from a seed, one chunk at a time.

unfoldChunks coalg = fromChunks . unfold coalg

Refold

refoldChunks :: Algebra (Cons Text) b -> Coalgebra (Cons Text) a -> a -> b Source #

Unfold then fold, fused — no intermediate Mu structure.

Mapping

mapChunks :: (Text -> Text) -> Text -> Text Source #

Map a function over each strict chunk.

Streaming

streamChunks :: (Mu (Cons Text) -> Mu (Cons Text)) -> Text -> Text Source #

Apply a streaming transformation to the chunks.

transformChunks :: (Mu (Cons Text) -> Mu (Cons a)) -> Text -> [a] Source #

Apply a streaming transformation that changes the element type.