Skip to content

Tags

Tags

v0.1.0

Toggle v0.1.0's commit message
htlx: the collections library for Teal projects — list, tablex, seq a…

…nd ordered

What Penlight's tablex / List / seq / OrderedMap, Lua's table, lodash, Kotlin's
kotlin.collections, Go's slices / maps and Deno's @std/collections have in common,
written once for the two table shapes Teal has, as a package apart from htl so that a
change to a helper never makes anyone upgrade their toolchain.

Four modules, one per shape. `list` is arrays (`{T}`): walk, cut, order, combine,
split, set operations, random, ask. `tablex` is maps (`{K:V}`) plus the few functions
that are about any table — deep_copy, deep_equals, deep_merge and a read-only view,
freeze. `seq` is the lazy side over `function(): T` iterators: entry points from a
table or an endless rule, transforms that wrap without pulling, exits that pull to the
end. `ordered` is the pair of generic records, Map<K, V> and Set<T>, that remember
insertion order, which `pairs` does not.

The rules are the same across the four and are in the README: argument bugs raise;
`nil` never enters an array and ends a sequence; nothing is mutated except what exists
to mutate (push / pop / shuffle, and ordered's set / add / delete); a lookup that finds
nothing returns nil; `_by` takes a key function and a comparator is always the last,
optional argument, `<` as table.sort takes it; arrays come back as arrays; a map and an
array never share a signature. Two things Teal makes the caller spell are there too: a
function type followed by more parameters is parenthesised, and `ordered.map()` needs
the type on the variable.

Verified: `htl check .` 10 file(s), 0 error(s), 0 warning(s), 0 lint(s) [strict];
`htl test` 5 file(s), 293 passed, 0 failed. `htl fmt` is not run on ordered.tl and its
test: htl 0.4.0's formatter takes a line ending in a generic's closing `>` for an
unfinished binary expression and indents the next line, which is htl's to fix.