Lists extension for CEL — mirrors ext.Lists() from cel-go.
Provides extended list functions. Functions are registered into the environment and also available as built-ins.
Usage
env = Celixir.Environment.new() |> Celixir.Ext.Lists.register()
Celixir.eval!("lists.range(5)", env) # => [0, 1, 2, 3, 4]
Celixir.eval!("[3, 1, 2].distinct()", env) # => [3, 1, 2]
Celixir.eval!("[1, 2, 2].distinct()", env) # => [1, 2]
Celixir.eval!("[1, 2, 3].first().value()", env) # => 1
Celixir.eval!("[1, 2, 3].last().value()", env) # => 3
Celixir.eval!("[3, 1, 2].sort()", env) # => [1, 2, 3]
Celixir.eval!("[3, 1, 2].reverse()", env) # => [2, 1, 3]
Celixir.eval!("[1, [2, 3]].flatten()", env) # => [1, 2, 3]
Celixir.eval!("[1, [2, [3]]].flatten(1)", env)# => [1, 2, [3]]Two-variable comprehensions (parser macros, always available)
list.sortBy(e, e.field)— sort list by computed key expressionlist.transformMapEntry(k, v, {v: k})— build map with custom key-value pairs
Functions
lists.range(int)— generate [0, 1, ..., n-1]list.distinct()— deduplicate preserving orderlist.first()— optional first elementlist.last()— optional last elementlist.slice(int, int)— sub-listlist.flatten()/list.flatten(int)— recursive flatten with optional depthlist.sort()— sort comparable elementslist.reverse()— reverse
Summary
Functions
Registers list extension functions into the given environment.