Skip to content

Lists#

Lists in CEL are ordered collections of values.

Literals#

Create lists using square brackets.

[1, 2, 3]
// result: [1, 2, 3] (list)
[]
// result: [] (list)

Lists can contain heterogeneous types.

[1, "two", true]
// result: [1, "two", true] (list)

Lists can be nested.

[[1, 2], [3, 4]]
// result: [[1, 2], [3, 4]] (list)

Size#

size() returns the number of elements. Both function and method syntax are supported.

size([1, 2, 3])
// result: 3 (int)
[1, 2, 3].size()
// result: 3 (int)

Indexing#

Access elements by index using square brackets. Indices start at zero.

["a", "b", "c"][0]
// result: "a" (string)
["a", "b", "c"][2]
// result: "c" (string)

Out-of-bounds access produces a runtime error.

[1, 2, 3][5]
// error: index out of bounds: 5

Nested lists use chained indexing.

[[1, 2], [3, 4]][0][1]
// result: 2 (int)

Membership#

The in operator checks if an element exists in a list.

2 in [1, 2, 3]
// result: true (bool)
5 in [1, 2, 3]
// result: false (bool)

Concatenation#

The + operator joins lists together.

[1, 2] + [3, 4]
// result: [1, 2, 3, 4] (list)

Comparison#

Lists support equality comparison. Two lists are equal if they have the same elements in the same order.

[1, 2, 3] == [1, 2, 3]
// result: true (bool)
[1, 2, 3] == [3, 2, 1]
// result: false (bool)

See also#