data.tables
rows of data under named columns, like a spreadsheet: filter rows, pick, change or add columns, sort
A table is a grid of rows under named columns, like a spreadsheet. Make one from a list of maps, where each map is a row and its keys are the column names.
good to know
Section titled “good to know”Listing a directory, globbing files and reading CSV all give tables. List functions work on tables too, and see each row as a map.
Tags: collections
tablea table from a list of maps, one map per rowwherekeep only the rows that pass the test f, which gets each row as a mapselectkeep only the named columns, in the order givenrejectremove the named columnsupdatea new table with one column’s cells replaced by f(cell)inserta new table with an added last column col, holding f(row) for each row, where the row is a mapsort_bythe rows sorted by the values in a column, smallest firstsort_by_descthe rows sorted by the values in a column, largest first
1# table2[{a: 1, b: 2}] to tabletable([{a: 1, b: 2}])syntax
Section titled “syntax”1# t.col: a column, as a list2[{a: 1}, {a: 2}].table.a[1, 2]3# t[i]: a row, as a map4[{a: 1}, {a: 2}].table[1]{a: 2}pretty
Section titled “pretty”1# long, the default: a grid2pretty([{a: 1234, b: "x"}].table) # a b
────────────
0 1,234 x
────────────
1 row · 2 columns3# short: all on one line, as a list of maps4pretty([{a: 1234, b: "x"}].table, "short")"table([{a: 1.23K, b: \"x\"}])"Functions
Section titled “Functions”table(rows: list|table) -> table
a table from a list of maps, one map per row
Every key that appears becomes a column, and rows without it get nil there
1[{a: 1}, {a: 2, b: 3}].tabletable([{a: 1, b: nil}, {a: 2, b: 3}])2[{a: 1}] to tabletable([{a: 1}])where(t: table, f: fn) -> table
keep only the rows that pass the test f, which gets each row as a map
1[{n: 1}, {n: 5}].table.where(|r| r.n > 2)table([{n: 5}])select
Section titled “select”select(t: table, *cols: str) -> table
keep only the named columns, in the order given
1[{a: 1, b: 2, c: 3}].table.select("c", "a")table([{c: 3, a: 1}])See also reject
reject
Section titled “reject”reject(t: table, *cols: str) -> table
remove the named columns
1[{a: 1, b: 2, c: 3}].table.reject("b")table([{a: 1, c: 3}])update
Section titled “update”update(t: table, col: str, f: fn) -> table
a new table with one column’s cells replaced by f(cell)
If f takes two params it also gets the row as a map, so a cell can be worked out from the others
1[{n: 1}, {n: 5}].table.update("n", _ * 10)table([{n: 10}, {n: 50}])2[{a: 2, b: 3}].table.update("b", |v, r| v * r.a)table([{a: 2, b: 6}])insert
Section titled “insert”insert(t: table, col: str, f: fn) -> table
a new table with an added last column col, holding f(row) for each row, where the row is a map
The column must not exist yet, use update to change one
1[{a: 2, b: 3}].table.insert("total", |r| r.a + r.b)table([{a: 2, b: 3, total: 5}])sort_by
Section titled “sort_by”sort_by(t: table, col: str) -> table
the rows sorted by the values in a column, smallest first
1[{n: 3}, {n: 1}].table.sort_by("n")table([{n: 1}, {n: 3}])Tags: sorting
See also sort_by_desc, sort
sort_by_desc
Section titled “sort_by_desc”sort_by_desc(t: table, col: str) -> table
the rows sorted by the values in a column, largest first
1[{n: 1}, {n: 3}].table.sort_by_desc("n")table([{n: 3}, {n: 1}])Tags: sorting
See also sort_by
More examples
Section titled “More examples”tables
Section titled “tables”1# a column as a list2[{n: 1}, {n: 5}].table.n[1, 5]3# list functions see each row as a map4[{n: 1}, {n: 5}].table.map(|r| r.n * 2)[2, 10]5# sort, then take one column6[{f: "a", kb: 3}, {f: "b", kb: 9}].table.sort_by_desc("kb").f["b", "a"]Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.