Skip to content

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.

  • len how many items a list, map or set has, characters a string has, or bytes a bytes value has
  • contains 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
  • find the position of the first x in v, counting from 0, or nil if it isn’t there
  • count how many times x appears in a string or list
  • reverse reverse a string or list
  • sort a sorted copy, smallest first
  • sort_desc a sorted copy, largest first, with the function working as in sort
  • unique drop repeated items, keeping the first of each in its place
  • first the first item, or nil if the list is empty
  • last the last item, or nil if the list is empty
  • take the first n items or characters
  • drop everything except the first n items or characters
  • any whether at least one item passes the test f, or without f, whether any item is itself truthy
  • all whether every item passes the test f, or without f, whether every item is itself truthy
1
# list
2
[1, 2, 3]
3
# map
4
{a: 1, b: 2}
Example outputCtrl+Enter to run
1
# x in v: is x an item of a list or set, or a key of a map?
2
2 in [1, 2]true
Example outputCtrl+Enter to run
1
# long, the default: one item per line
2
pretty([1234567, "a"])
[ 1,234,567 "a" ]
3
# short: all on one line, each item short
4
pretty([1234567, "a", {b: 2500 g}], "short")"[1.23M, \"a\", {b: 2.5 kg}]"
Example outputCtrl+Enter to run
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".len5
2
[1, 2, 3].len3
3
{a: 1}.len1
Example outputCtrl+Enter to run
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+")true
2
[1, 2].contains(2)true
Example outputCtrl+Enter to run

Tags: 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")2
2
[5, 6].find(6)1
3
"abc".find("z")nil
Example outputCtrl+Enter to run

Tags: searching

See also contains, count

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")3
2
[1, 2, 1].count(1)2
Example outputCtrl+Enter to run

Tags: searching

See also find

reverse(v: str|list) -> str|list

reverse a string or list

1
"abc".reverse"cba"
2
[1, 2, 3].reverse[3, 2, 1]
Example outputCtrl+Enter to run

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"]
Example outputCtrl+Enter to run

Tags: sorting

See also reverse, unique

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"]
Example outputCtrl+Enter to run

Tags: sorting

See also sort

unique(xs: list) -> list

drop repeated items, keeping the first of each in its place

1
[1, 2, 1, 3].unique[1, 2, 3]
Example outputCtrl+Enter to run

Tags: collections

See also sort, count

first(xs: list) -> any

the first item, or nil if the list is empty

1
[7, 8].first7
Example outputCtrl+Enter to run

Tags: collections

See also last

last(xs: list) -> any

the last item, or nil if the list is empty

1
[7, 8].last8
Example outputCtrl+Enter to run

Tags: 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"
Example outputCtrl+Enter to run

Tags: collections

See also drop, first

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"
Example outputCtrl+Enter to run

Tags: collections

See also take, last

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)true
2
[nil, false].anyfalse
Example outputCtrl+Enter to run

Tags: searching

See also all, filter

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)true
2
[].alltrue
Example outputCtrl+Enter to run

Tags: searching

See also any, filter

1
# drop repeats, keeping the order
2
[3, 1, 3, 2, 1].unique[3, 1, 2]
3
# sort lengths in different units
4
[1 km, 900 m, 1 mi].sort[900 m, 1 km, 1 mi]
5
# sort dates
6
[date("2026-12-25"), date("2026-01-01")].sort[2026-01-01, 2026-12-25]
Example outputCtrl+Enter to run

Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.