Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

data

sorting and searching any collection; lists, maps, tables, charts below

Example results generated on 2026-10-08. Ones using now, today or randomness will differ when you run them: press Run on any example to run it in your browser, after editing it if you like.

types

# list
[1, 2, 3]
# map
{a: 1, b: 2}

operators

# x in v
2 in [1, 2]
# → true

pretty

# long: one item per line, indented, items pretty, strings quoted
# short: one line, items short
pretty([1234567, "a", {b: 2500 g}], "short")
# → "[1.23M, \"a\", {b: 2.5 kg}]"

Submodules

moduleabout
listsranges, map/filter/reduce, building lists
mapskeys, values, lookups, merging and transforming maps
setsunique values in insertion order: union, intersection, difference
tablesrows under named columns: filter, pick columns, sort
chartssparklines, bar charts, histograms, plots, heatmaps, progress bars and trees

Functions

functiondescription
len(v: str|list|map|set)length of a string, list, map or set
contains(v: str|list|map|set, x: any)substring/regex in a string, item in a list or set, key in a map
find(v: str|list, x: any)index of the first match, or nil
count(v: str|list, x: any)number of matches in a string or list
reverse(v: str|list)reverse a string or list
sort(xs: list|set, key?: fn)sorted list, optionally by key function
sort_desc(xs: list|set, key?: fn)like sort, largest first
unique(xs: list)drop duplicates, keeping first occurrences
first(xs: list)first item, or nil
last(xs: list)last item, or nil
take(v: str|list, n: int)the first n items or characters
drop(v: str|list, n: int)everything after the first n items or characters
any(xs: list, f?: fn)true if f (or the item itself) is truthy for some item
all(xs: list, f?: fn)true if f (or the item itself) is truthy for every item

len

len(v: str|list|map|set): length of a string, list, map or set

"héllo".len
# → 5
[1, 2, 3].len
# → 3
{a: 1}.len
# → 1

contains

contains(v: str|list|map|set, x: any): substring/regex in a string, item in a list or set, key in a map

"price: $12".contains(r"\$\d+")
# → true
[1, 2].contains(2)
# → true

See also: find, starts_with

find

find(v: str|list, x: any): index of the first match, or nil

"hello".find("l")
# → 2
[5, 6].find(6)
# → 1
"abc".find("z")
# → nil

See also: contains, count

count

count(v: str|list, x: any): number of matches in a string or list

"banana".count("a")
# → 3
[1, 2, 1].count(1)
# → 2

See also: find

reverse

reverse(v: str|list): reverse a string or list

"abc".reverse
# → "cba"
[1, 2, 3].reverse
# → [3, 2, 1]

See also: sort

sort

sort(xs: list|set, key?: fn): sorted list, optionally by key function

[3, 1, 2].sort
# → [1, 2, 3]
["ccc", "a", "bb"].sort(|w| w.len)
# → ["a", "bb", "ccc"]

See also: reverse, unique

sort_desc

sort_desc(xs: list|set, key?: fn): like sort, largest first

[3, 1, 2].sort_desc
# → [3, 2, 1]
["bb", "a", "ccc"].sort_desc(|w| w.len)
# → ["ccc", "bb", "a"]

See also: sort

unique

unique(xs: list): drop duplicates, keeping first occurrences

[1, 2, 1, 3].unique
# → [1, 2, 3]

See also: sort, count

first

first(xs: list): first item, or nil

[7, 8].first
# → 7

See also: last

last

last(xs: list): last item, or nil

[7, 8].last
# → 8

See also: first

take

take(v: str|list, n: int): the first n items or characters

[1, 2, 3].take(2)
# → [1, 2]
"hello".take(3)
# → "hel"

See also: drop, first

drop

drop(v: str|list, n: int): everything after the first n items or characters

[1, 2, 3].drop(2)
# → [3]
"hello".drop(3)
# → "lo"

See also: take, last

any

any(xs: list, f?: fn): true if f (or the item itself) is truthy for some item

[0, 5, 12].any(|x| x > 10)
# → true
[nil, false].any
# → false

See also: all, filter

all

all(xs: list, f?: fn): true if f (or the item itself) is truthy for every item

[2, 4, 6].all(|x| x % 2 == 0)
# → true
[].all
# → true

See also: any, filter

More examples

data

# unique, order kept
[3, 1, 3, 2, 1].unique
# → [3, 1, 2]
# sort quantities
[1 km, 900 m, 1 mi].sort
# → [900 m, 1 km, 1 mi]
# sort dates
[date("2026-12-25"), date("2026-01-01")].sort
# → [2026-01-01, 2026-12-25]