Skip to content

All#

The e.all(x, p) macro tests whether predicate p is true for every element x in collection e.

Lists#

Returns true if the predicate is true for all elements.

[1, 2, 3].all(x, x > 0)
// result: true (bool)
[1, 2, 3].all(x, x > 1)
// result: false (bool)

An empty list returns true.

[].all(x, x > 0)
// result: true (bool)

Maps#

When applied to a map, all iterates over the keys.

// input: scores = {"alice": 95, "bob": 87}
scores.all(name, scores[name] >= 80)
// result: true (bool)

An empty map returns true.

{}.all(k, k != "x")
// result: true (bool)

Short-circuit evaluation#

Evaluation stops at the first false result.

[-1, 0, 1].all(x, 1 / x > 0)
// result: false (bool)

The first element produces false so evaluation stops before erroring with a divide-by-zero error.

See also#