Lists

Lists in RuLA are ordered collections of values. They can contain any type of value: strings, numbers, other lists, or dictionaries.

Creating Lists

Use square brackets with comma-separated values:

['apple', 'banana', 'cherry']           # List of strings
[1, 2, 3, 4, 5]                          # List of numbers
[]                                       # Empty list
['text', 42, {'key': 'value'}]          # Mixed types

Accessing List Elements

Access elements by index (0-based):

fruits = ['apple', 'banana', 'cherry']
fruits[0]           # Returns 'apple'
fruits[2]           # Returns 'cherry'

List Manipulation

Adding Elements

APPEND([1, 2], 3)             # Returns [1, 2, 3]
CONCAT([1, 2], [3, 4])        # Concatenation: [1, 2, 3, 4]

Filtering

Transforming (Mapping)

Sorting and Reversing

Getting Unique Elements

Flattening Nested Lists

Useful List Functions

Function
Description
Example

Number of elements

COUNT([1, 2, 3]) β†’ 3

Sort in ascending order

SORT([3, 1, 2]) β†’ [1, 2, 3]

Reverse the order

REVERSE([1, 2, 3]) β†’ [3, 2, 1]

Get first element

FIRST_ELEMENT([1, 2, 3]) β†’ 1

Get last element

LAST_ELEMENT([1, 2, 3]) β†’ 3

Add element to end

APPEND([1, 2], 3) β†’ [1, 2, 3]

Find position (0-based)

INDEX_OF(['a', 'b'], 'b') β†’ 1

Remove duplicates

SET([1, 1, 2]) β†’ [1, 2]

Flatten one level

FLATTEN([[1], [2]]) β†’ [1, 2]

Combine unique elements

UNION([1, 2], [2, 3]) β†’ [1, 2, 3]

Common elements

INTERSECTION([1, 2], [2, 3]) β†’ [2]

Elements in list1 not in list2

SET_DIFFERENCE([1, 2], [2, 3]) β†’ [1]

Sum of numbers

SUM([1, 2, 3]) β†’ 6

Average of numbers

AVG([1, 2, 3]) β†’ 2

Minimum value

MIN([3, 1, 2]) β†’ 1

Maximum value

MAX([3, 1, 2]) β†’ 3

Join all strings

CONCAT(['a', 'b']) β†’ "ab"

Join with separator

JOIN(['a', 'b'], '-') β†’ "a-b"

Transform each element

MAP([1, 2], x => x * 2) β†’ [2, 4]

Keep matching elements

FILTER([1, 2, 3], x => x > 1) β†’ [2, 3]

All values true?

ALL([true, true, false]) β†’ False

Any value true?

ANY([true, true, false]) β†’ True

Any value true? (alias for ANY)

SOME([true, false]) β†’ True

Max element ranked by an ordering list

CUSTOM_MAX([red, green], [green, red]) β†’ red

Checking List Contents

List Operations on Aggregated Data

Last updated

Was this helpful?