Reference · Maps

values

signature
values(map | null) -> list

What it does

The values of a map as a list, in the order the entries were added. Each value is itself, whatever its type: a nested map or list is not copied or flattened. null counts as an empty map and gives [].

Examples

let prices = { apple: 2, pear: 3, fig: 5 }print(values(prices))print(values(prices) | sum)
output
[2, 3, 5]10

Edge cases

let m = { a: [1], b: { c: 2 }, d: null }print(values(m))print(zip(keys(m), values(m)))print(values({}), values(null))
output
[[1], { c: 2 }, null][["a", [1]], ["b", { c: 2 }], ["d", null]][] []

Errors

Anything but a map or null is a runtime error, not an error value.

this one fails
print(values("ab"))
output
line 1: `values` expects a map as argument 1, got str

Chaining

print({ a: 3, b: 1, c: 2 } | values | sort)print({ a: 1, b: 2 } | values | map((v) => v * 10))
output
[1, 2, 3][10, 20]

See also

keys, get, zip, sum

Thread
8Useful? Like it, or add to its thread below.

Thread 0 posts

On values(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo