Module

pooka/string_tree

src/pooka/string_tree.pooka

Keep the pieces until somebody asks for the whole parcel. Appending makes a branch in constant time. Rendering walks an explicit work list, preserving chunk order without recursive calls down a deep left spine. Text stays UTF-8; byte counts describe encoding, not visible characters.

Pooka
assert string_tree.to_string(string_tree.from_string("oak")) == "oak"

API reference

class

StringTree

src/pooka/string_tree.pooka:18
class StringTree

An immutable tree. Only the private leaf and branch classes construct its values.

function

new

src/pooka/string_tree.pooka:27
new() -> StringTree

Start without any chunks.

function

from_string

src/pooka/string_tree.pooka:32
from_string(value: String) -> StringTree
INFERREDfn(String) -> pooka/string_tree.StringTree

Keep a chunk without copying its contents.

function

append

src/pooka/string_tree.pooka:41
append(tree: StringTree, value: String) -> StringTree

Attach one chunk in constant time.

Pooka
assert string_tree.to_string(string_tree.append(string_tree.new(), "oak")) == "oak"
function

append_tree

src/pooka/string_tree.pooka:46
append_tree(left: StringTree, right: StringTree) -> StringTree

Attach another tree without walking either side.

function

prepend

src/pooka/string_tree.pooka:51
prepend(tree: StringTree, value: String) -> StringTree

Place one chunk before the earlier tree.

function

concat

src/pooka/string_tree.pooka:56
concat(trees: List(StringTree)) -> StringTree

Join trees in input order without rendering their chunks.

function

from_strings

src/pooka/string_tree.pooka:61
from_strings(values: List(String)) -> StringTree
INFERREDfn(List(String)) -> pooka/string_tree.StringTree

Keep each supplied chunk as a leaf.

function

to_string

src/pooka/string_tree.pooka:66
to_string(tree: StringTree) -> String
INFERREDfn(pooka/string_tree.StringTree) -> String

Render once, preserving every chunk's order.

function

byte_size

src/pooka/string_tree.pooka:71
byte_size(tree: StringTree) -> Int
INFERREDfn(pooka/string_tree.StringTree) -> Int

Count encoded bytes without joining the chunks.

function

is_empty

src/pooka/string_tree.pooka:78
is_empty(tree: StringTree) -> Bool
INFERREDfn(pooka/string_tree.StringTree) -> Bool

Ask whether rendering would produce an empty value.