Zafu/Text/Pretty

Zafu/Text/Pretty

source code:

public dependencies: Zafu/Abstract/Monoid, Zafu/Collection/LazyList

Index

Types

Doc

type Doc

Document[a]

Typeclass-style dictionary for rendering a values into Doc. Input: to_doc_fn converts one a value to a document. Output: a reusable renderer instance for type a.

type Document[a: -*]

Values

aligned

Aligns doc to the current rendering column. Input: any document. Output: aligned document node.

references: Doc

def aligned(doc: Doc) -> Doc

ansi_control

Builds ANSI escape output as zero-width control text. Input: list of numeric ANSI codes. Output: zero-width \u001b[<codes>m sequence.

references: Doc, Int, List

def ansi_control(codes: List[Int]) -> Doc

append

Concatenates two documents in O(1). Input: left and right documents. Output: combined document preserving both layouts.

references: Doc

def append(left: Doc, right: Doc) -> Doc

append_line

Concatenates with a soft line break between operands. Input: left and right documents. Output: left + line + right.

references: Doc

def append_line(left: Doc, right: Doc) -> Doc

append_line_or_space

Concatenates with line_or_space between operands. Input: left and right documents. Output: left + line_or_space + right.

references: Doc

def append_line_or_space(left: Doc, right: Doc) -> Doc

append_line_or_space_text

Concatenates with line_or_space before text. Input: left document and right string. Output: left + line_or_space + text(right).

references: Doc, String

def append_line_or_space_text(left: Doc, right: String) -> Doc

append_line_text

Concatenates with a soft line break before text. Input: left document and right string. Output: left + line + text(right).

references: Doc, String

def append_line_text(left: Doc, right: String) -> Doc

append_space

Concatenates with a space between operands. Input: left and right documents. Output: left + space + right.

references: Doc

def append_space(left: Doc, right: Doc) -> Doc

append_space_text

Concatenates with a space before text. Input: left document and right string. Output: left + space + text(right).

references: Doc, String

def append_space_text(left: Doc, right: String) -> Doc

append_text

Appends plain text after doc. Input: document prefix and string suffix. Output: doc followed by text(value).

references: Doc, String

def append_text(doc: Doc, value: String) -> Doc

bracket_by

Wraps doc between left and right with soft line spacing. Input: body doc, left delimiter, right delimiter, and nesting amount. Output: grouped bracketed document.

references: Doc, Int

def bracket_by(doc: Doc, left: Doc, right: Doc, amount: Int) -> Doc

by

Contramap/project combinator for Document. Input: renderer for b and projection from a to b. Output: renderer for a.

references: Document

def by[a, b](docu: Document[a], project: b -> a) -> Document[b]

cat

Concatenates docs with no separator. Input: list of docs. Output: all docs appended in order.

references: Doc, List

def cat(docs: List[Doc]) -> Doc

char

Converts one character to a document. Input: a character value. Output: line when the character is newline, otherwise a single-character text doc.

references: Char, Doc

def char(value: Char) -> Doc

comma

Comma text document. Output: a one-character comma Doc.

references: Doc

comma: Doc

document_Bool

Built-in Document for Bool. Output: True or False.

references: Bool, Document

document_Bool: Document[Bool]

document_Char

Built-in Document for Char. Output: uses char.

references: Char, Document

document_Char: Document[Char]

document_Float64

Built-in Document for Float64. Output: uses float.

references: Document, Float64

document_Float64: Document[Float64]

document_Int

Built-in Document for Int. Output: uses int.

references: Document, Int

document_Int: Document[Int]

document_List

Builds a Document instance for lists. Input: item renderer. Output: bracketed list document using fill(comma + line, ...).

references: Document, List

def document_List[a](item_doc: Document[a]) -> Document[List[a]]

document_Option

Builds a Document instance for options. Input: item renderer. Output: None or grouped Some(<item>).

references: Document, Option

def document_Option[a](item_doc: Document[a]) -> Document[Option[a]]

document_String

Built-in Document for String. Output: uses text.

references: Document, String

document_String: Document[String]

document_Unit

Built-in Document for Unit. Output: literal ().

references: Document, Unit

document_Unit: Document[()]

document_from_fn

Builds a Document[a] from a rendering function. Input: function from a to Doc. Output: Document[a] dictionary.

references: Doc, Document

def document_from_fn[a](fn: a -> Doc) -> Document[a]

empty

The empty document. Output: renders as the empty string and acts as append identity.

references: Doc

empty: Doc

fill

Width-sensitive separator folding like Paiges fill. Input: separator doc and item docs. Output: document that packs items onto lines when possible.

references: Doc, List

def fill(sep: Doc, docs: List[Doc]) -> Doc

flatten

Flattens all FlatAlt/Union behavior to single-line alternatives. Input: any document. Output: flattened document.

references: Doc

def flatten(doc: Doc) -> Doc

flatten_option

Attempts to flatten doc and returns None when flattening is a no-op. Input: any document. Output: Some(flat_doc) if structure changes, else None.

references: Doc, Option

def flatten_option(doc: Doc) -> Option[Doc]

float

Renders a float with deterministic parseable output. Input: a Float64. Output: NaN, Infinity, -Infinity, or the runtime shortest round-trippable decimal.

references: Doc, Float64

def float(value: Float64) -> Doc

fold_docs

Reduces docs from left to right using fn. Input: list of docs and a binary combine function. Output: reduced document, or empty for an empty list.

references: Doc, List

def fold_docs(docs: List[Doc], fn: (Doc, Doc) -> Doc) -> Doc

grouped

Adds an optimistic flat layout branch for doc. Input: a document with potential line breaks. Output: doc wrapped in Union(flatten(doc), doc) when flattening changes it.

references: Doc

def grouped(doc: Doc) -> Doc

hang

Applies nested and then aligned. Input: document and indent amount. Output: hanging-indented document.

references: Doc, Int

def hang(doc: Doc, amount: Int) -> Doc

hard_line

Mandatory line break. Output: always renders as newline plus current indentation.

references: Doc

hard_line: Doc

indent

Prefixes doc with amount spaces and hangs subsequent lines. Input: document and indent amount. Output: indented document.

references: Doc, Int

def indent(doc: Doc, amount: Int) -> Doc

int

Renders an integer in canonical base-10 form. Input: an Int. Output: decimal text with optional leading -.

references: Doc, Int

def int(value: Int) -> Doc

intercalate

Inserts sep between each document in docs. Input: separator doc and items. Output: concatenated document with separator between neighbors.

references: Doc, List

def intercalate(sep: Doc, docs: List[Doc]) -> Doc

is_empty

Checks whether doc has no visible output. Input: any document. Output: True only when rendering produces no text or line breaks.

references: Bool, Doc

def is_empty(doc: Doc) -> Bool

line

Soft line break that becomes a space in flattened layouts. Output: newline in broken mode, " " in flat mode.

references: Doc

line: Doc

line_break

Soft line break that disappears in flattened layouts. Output: newline in broken mode, empty in flat mode.

references: Doc

line_break: Doc

line_or

Chooses between a real line break and flattened doc. Input: fallback document used in flat mode. Output: document that renders as newline or flattened fallback based on grouping.

references: Doc

def line_or(doc: Doc) -> Doc

line_or_empty

Line-or-empty convenience value. Output: newline in broken layouts, empty in flat layouts.

references: Doc

line_or_empty: Doc

line_or_space

Line-or-space convenience value. Output: newline in broken layouts, space in flat layouts.

references: Doc

line_or_space: Doc

max_width

Computes the maximum rendered line width of doc. Input: any document. Output: maximum column width reached across all lines.

references: Doc, Int

def max_width(doc: Doc) -> Int

monoid_Doc

Monoid on Doc where append is the combine

references: Doc, Zafu/Abstract/Monoid::Monoid

monoid_Doc: Zafu/Abstract/Monoid::Monoid[Doc]

nested

Increases indentation level for doc. Input: document and indent amount. Output: a nested document with added indentation.

references: Doc, Int

def nested(doc: Doc, amount: Int) -> Doc

non_empty

Negation of is_empty. Input: any document. Output: True when doc has visible output.

references: Bool, Doc

def non_empty(doc: Doc) -> Bool

paragraph

Alias for split. Input: source string paragraph. Output: reflowable paragraph document.

references: Doc, String

def paragraph(value: String) -> Doc

prepend_text

Prepends plain text before doc. Input: string prefix and document suffix. Output: text(value) followed by doc.

references: Doc, String

def prepend_text(value: String, doc: Doc) -> Doc

render

Renders doc at width. Input: document and target width. Output: lazy chunk stream in rendering order.

references: Doc, Int, String, Zafu/Collection/LazyList::LazyList

def render(doc: Doc, width: Int) -> Zafu/Collection/LazyList::LazyList[String]

render_String

references: Doc, Int, String

def render_String(doc: Doc, width: Int) -> String

render_stream

Renders doc to a stream of chunks with bounded layout selection. Input: document and target width. Output: lazy chunk stream whose concatenation is the rendered text.

references: Doc, Int, String, Zafu/Collection/LazyList::LazyList

def render_stream(doc: Doc, width: Int) -> Zafu/Collection/LazyList::LazyList[String]

render_stream_trim

Chunk-stream form of render_trim. Input: document and target width. Output: lazy chunk stream containing trimmed rendering output.

references: Doc, Int, String, Zafu/Collection/LazyList::LazyList

def render_stream_trim(doc: Doc, width: Int) -> Zafu/Collection/LazyList::LazyList[String]

render_trim

Renders doc and trims trailing spaces on each line. Input: document and target width. Output: lazy chunk stream with right-trimmed lines.

references: Doc, Int, String, Zafu/Collection/LazyList::LazyList

def render_trim(doc: Doc, width: Int) -> Zafu/Collection/LazyList::LazyList[String]

render_wide_stream

Renders without bounded fits checks (always picks flattened union branch). Input: document. Output: lazy chunk stream rendered in wide mode.

references: Doc, String, Zafu/Collection/LazyList::LazyList

def render_wide_stream(doc: Doc) -> Zafu/Collection/LazyList::LazyList[String]

repeat

Repeats doc count times using a logarithmic doubling strategy. Input: document doc and repeat count count. Output: empty for non-positive counts, else left-associated repetition of doc.

references: Doc, Int

def repeat(doc: Doc, count: Int) -> Doc

representation

Returns a structural debug representation of doc. Input: any document. Output: text document describing internal node structure.

references: Doc

def representation(doc: Doc) -> Doc

space

Single space text document. Output: a one-character space Doc.

references: Doc

space: Doc

spaces

Creates a document containing width spaces. Input: number of spaces to emit. Output: repeat(space, width).

references: Doc, Int

def spaces(width: Int) -> Doc

split

Splits text into words and rejoins with line_or_space. Input: source string with arbitrary whitespace. Output: reflowable paragraph document.

references: Doc, String

def split(value: String) -> Doc

spread

Concatenates docs separated by space. Input: list of docs. Output: space-separated document.

references: Doc, List

def spread(docs: List[Doc]) -> Doc

stack

Concatenates docs separated by line. Input: list of docs. Output: line-separated document.

references: Doc, List

def stack(docs: List[Doc]) -> Doc

tabulate

Convenience tabulate_with using space fill and empty key suffix. Input: (key, doc) rows. Output: aligned table document.

references: Doc, List, String, Tuple2

def tabulate(rows: List[(String, Doc)]) -> Doc

tabulate_with

Builds aligned key/value rows with configurable fill character and key suffix. Input: key fill character, right-side separator text, and (key, doc) rows. Output: multi-line aligned table document.

references: Char, Doc, List, String, Tuple2

def tabulate_with(fill_char: Char, right_sep: String, rows: List[(String, Doc)]) -> Doc

text

Converts value into a Doc where \n uses line. Input: any string, including embedded newlines. Output: a width-sensitive document equivalent to text_with_line(value, line).

references: Doc, String

def text(value: String) -> Doc

text_with_line

+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+ Exported constructors and combinators +#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+ Converts value into a Doc, replacing each \n with line_doc. Input: value string and line_doc separator used between split lines. Output: concatenated document preserving empty leading/trailing lines.

references: Doc, String

def text_with_line(value: String, line_doc: Doc) -> Doc

tight_bracket_by

Wraps doc between left and right without flat-mode interior spaces. Input: body doc, left delimiter, right delimiter, and nesting amount. Output: grouped tightly bracketed document.

references: Doc, Int

def tight_bracket_by(doc: Doc, left: Doc, right: Doc, amount: Int) -> Doc

to_Doc

Applies a Document[a] renderer to one value. Input: document dictionary and item value. Output: rendered Doc for that value.

references: Doc, Document

def to_Doc[a](docu: Document[a], value: a) -> Doc

unzero

Removes all zero-width nodes from doc. Input: any document. Output: document with ZeroWidth replaced by empty.

references: Doc

def unzero(doc: Doc) -> Doc

zero_width

Inserts zero-width text into output. Input: value bytes to emit without affecting layout width. Output: empty when value is empty, else a zero-width node.

references: Doc, String

def zero_width(value: String) -> Doc