Skip to main content
The array module is how you build and transform lists in Lion. Because every Lion expression is valid JSON, arrays play a dual role: they are both executable expressions and data. The array/make function lets you treat an array as data — collecting its arguments into a list — without triggering the evaluator’s call semantics.

Construction and access

array/make

Collects its arguments into an array. This is the canonical way to produce a literal list in a Lion program.
Result: [1, 2, 3]

array/head

Returns the first element of an array. Throws when the array is empty.
Result: 1

array/tail

Returns all elements after the first. Throws when the array is empty.
Result: [2, 3]

array/length

Returns the number of elements in an array.
Result: 3

Combining arrays

array/concat

Concatenates two arrays and returns the combined list.
Result: [1, 2, 3, 4]

array/includes?

Returns true when the array contains the given value. Uses Effect’s Equal.equals for comparison, which falls back to referential equality (===) for plain JavaScript values.
Result: true

Higher-order functions

All three higher-order functions accept a Lion lambda as their function argument, so they integrate with the Lion evaluator rather than requiring plain JavaScript functions.

array/map

Applies a function to every element and returns the transformed array.
Result: [2, 3, 4]

array/flat-map

Applies a function to every element and flattens the resulting arrays by one level.
Result: [1, 1, 2, 2]

array/reduce

Folds a list into a single value. Arguments are: the array, the initial accumulator, and a two-argument function that receives the accumulator and the current element.
Result: 6
array/map, array/flat-map, and array/reduce run each callback through the Lion evaluator. This means you can use any Lion expression — including nested function calls and begin blocks — inside a lambda passed to these functions.
Combine array/reduce with array/concat to flatten nested structures, or use array/flat-map when each element maps to a variable-length list.