APIText.Builder
Text.Builder
Text assembled by appending.
A builder is immutable: appending returns a new builder and leaves the old one answering exactly the text it had, whichever builders extend it, in whatever order, and from whichever tasks. Appending in sequence costs amortized time proportional to the text appended.
Append operations take the text or scalar first and the builder last, so
they compose with |>.
import Text.Builder
built = Text.Builder.empty |> Text.Builder.append "foo" |> Text.Builder.appendInt 123
Text.Builder.toString built == "foo123"
Builder
type BuilderSource
Text built by appending. Builders have no equality or display; compare or
show their toString.
append
append : String -> Builder -> BuilderSource
The builder with text appended. Extending the most recently extended
builder reuses available storage; extending an older one copies its text.
import Text.Builder
base = Text.Builder.append "a" Text.Builder.empty
left = Text.Builder.append "b" base
right = Text.Builder.append "c" base
Text.Builder.toString left == "ab"
Text.Builder.toString right == "ac"
Text.Builder.toString base == "a"
appendChar
appendChar : Char -> Builder -> BuilderSource
The builder with one character appended.
import Text.Builder
Text.Builder.toString (Text.Builder.appendChar 'k' (Text.Builder.append "o" Text.Builder.empty)) == "ok"
appendCharLiteral
appendCharLiteral : Char -> Builder -> BuilderSource
Appends the quoted, escaped source representation of a Char, without an
intermediate string. Its spelling agrees with show.
appendFloat
appendFloat : Float -> Builder -> BuilderSource
The builder with a float’s display appended without an intermediate string.
Its spelling is the same as show: shortest round-trip decimals, unpadded
exponents outside the ordinary decimal range, Infinity, and NaN.
import Text.Builder
Text.Builder.toString (Text.Builder.appendFloat 1.25 Text.Builder.empty) == "1.25"
appendInt
appendInt : Int -> Builder -> BuilderSource
The builder with an integer’s decimal display appended without an intermediate string.
import Text.Builder
Text.Builder.toString (Text.Builder.appendInt (-42) Text.Builder.empty) == "-42"
appendStringLiteral
appendStringLiteral : String -> Builder -> BuilderSource
Appends the quoted, escaped source representation of a String, without an
intermediate string. Its spelling agrees with show.
charLiteral
charLiteral : Char -> StringSource
The quoted, escaped source representation of a character.
charToString
charToString : Char -> StringSource
A string containing one character, without quoting or escaping.
empty
empty : BuilderSource
The builder holding no text.
floatToString
floatToString : Float -> StringSource
The float representation used by appendFloat, without allocating a builder.
intToString
intToString : Int -> StringSource
The decimal representation of an integer, without allocating a builder.
isEmpty
isEmpty : Builder -> BoolSource
Whether the builder holds no text.
import Text.Builder
Text.Builder.isEmpty Text.Builder.empty
Text.Builder.isEmpty (Text.Builder.append "" Text.Builder.empty)
stringLiteral
stringLiteral : String -> StringSource
The quoted, escaped source representation of a string, including escaping #{.
toString
toString : Builder -> StringSource
The text the builder holds, copied once.
