data
work with collections of values: sort, search and pick from lists, maps, sets and tables, and chart them
Collections hold many values at once: lists keep order, maps pair keys with values, sets drop repeats, and tables are rows of named columns. The functions here work on any of them, and the submodules cover what is specific to each.
lenhow many items a list, map or set has, characters a string has, or bytes a bytes value hascontainswhether x is in v: text (or a regex match) in a string, an item in a list or set, or a key in a mapfindthe position of the first x in v, counting from 0, or nil if it isn’t therecounthow many times x appears in a string or listreversereverse a string or listsorta sorted copy, smallest firstsort_desca sorted copy, largest first, with the function working as in sortuniquedrop repeated items, keeping the first of each in its placefirstthe first item, or nil if the list is emptylastthe last item, or nil if the list is emptytakethe first n items or charactersdropeverything except the first n items or charactersanywhether at least one item passes the test f, or without f, whether any item is itself truthyallwhether every item passes the test f, or without f, whether every item is itself truthy
1# list2[1, 2, 3]3# map4{a: 1, b: 2}syntax
Section titled “syntax”1# x in v: is x an item of a list or set, or a key of a map?22 in [1, 2]truepretty
Section titled “pretty”1# long, the default: one item per line2pretty([1234567, "a"])[
1,234,567
"a"
]3# short: all on one line, each item short4pretty([1234567, "a", {b: 2500 g}], "short")"[1.23M, \"a\", {b: 2.5 kg}]"Functions
Section titled “Functions”len(v: str|bytes|list|map|set) -> int
how many items a list, map or set has, characters a string has, or bytes a bytes value has
1"héllo".len52[1, 2, 3].len33{a: 1}.len1contains
Section titled “contains”contains(s: str, x: str|regex) -> bool / contains(xs: list|set, x: any) -> bool / contains(m: map, k: str) -> bool
whether x is in v: text (or a regex match) in a string, an item in a list or set, or a key in a map
1"price: $12".contains(r"\$\d+")true2[1, 2].contains(2)trueTags: searching
See also find, starts_with
find(s: str, x: str|regex) -> int|nil / find(xs: list, x: any) -> int|nil
the position of the first x in v, counting from 0, or nil if it isn’t there
1"hello".find("l")22[5, 6].find(6)13"abc".find("z")nilTags: searching
count(s: str, x: str|regex) -> int / count(xs: list, x: any) -> int
how many times x appears in a string or list
1"banana".count("a")32[1, 2, 1].count(1)2Tags: searching
See also find
reverse
Section titled “reverse”reverse(v: str|list) -> str|list
reverse a string or list
1"abc".reverse"cba"2[1, 2, 3].reverse[3, 2, 1]Tags: sorting
See also sort
sort(xs: list|set, key?: fn) -> list
a sorted copy, smallest first
Given a function, items are sorted by what it returns for each, like |w| w.len to sort words by length
1[3, 1, 2].sort[1, 2, 3]2["ccc", "a", "bb"].sort(|w| w.len)["a", "bb", "ccc"]Tags: sorting
sort_desc
Section titled “sort_desc”sort_desc(xs: list|set, key?: fn) -> list
a sorted copy, largest first, with the function working as in sort
1[3, 1, 2].sort_desc[3, 2, 1]2["bb", "a", "ccc"].sort_desc(|w| w.len)["ccc", "bb", "a"]Tags: sorting
See also sort
unique
Section titled “unique”unique(xs: list) -> list
drop repeated items, keeping the first of each in its place
1[1, 2, 1, 3].unique[1, 2, 3]Tags: collections
first(xs: list) -> any
the first item, or nil if the list is empty
1[7, 8].first7Tags: collections
See also last
last(xs: list) -> any
the last item, or nil if the list is empty
1[7, 8].last8Tags: collections
See also first
take(v: str|list, n: int) -> str|list
the first n items or characters
1[1, 2, 3].take(2)[1, 2]2"hello".take(3)"hel"Tags: collections
drop(v: str|list, n: int) -> str|list
everything except the first n items or characters
1[1, 2, 3].drop(2)[3]2"hello".drop(3)"lo"Tags: collections
any(xs: list, f?: fn) -> bool
whether at least one item passes the test f, or without f, whether any item is itself truthy
1[0, 5, 12].any(|x| x > 10)true2[nil, false].anyfalseTags: searching
all(xs: list, f?: fn) -> bool
whether every item passes the test f, or without f, whether every item is itself truthy
An empty list gives true
1[2, 4, 6].all(|x| x % 2 == 0)true2[].alltrueTags: searching
More examples
Section titled “More examples”1# drop repeats, keeping the order2[3, 1, 3, 2, 1].unique[3, 1, 2]3# sort lengths in different units4[1 km, 900 m, 1 mi].sort[900 m, 1 km, 1 mi]5# sort dates6[date("2026-12-25"), date("2026-01-01")].sort[2026-01-01, 2026-12-25]Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.