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):
List Manipulation¶
Adding Elements¶
Filtering¶
numbers = [1, 2, 3, 4, 5]
FILTER(numbers, x => x > 3) # Returns [4, 5]
FILTER_FALSE(true, false, true, false) # Returns [true, true]
Transforming (Mapping)¶
Sorting and Reversing¶
SORT([3, 1, 2]) # Returns [1, 2, 3]
SORT(['banana', 'apple']) # Returns ['apple', 'banana']
REVERSE([1, 2, 3]) # Returns [3, 2, 1]
Getting Unique Elements¶
Flattening Nested Lists¶
Useful List Functions¶
| Function | Description | Example |
|---|---|---|
COUNT |
Number of elements | COUNT([1, 2, 3]) â 3 |
SORT |
Sort in ascending order | SORT([3, 1, 2]) â [1, 2, 3] |
REVERSE |
Reverse the order | REVERSE([1, 2, 3]) â [3, 2, 1] |
FIRST_ELEMENT |
Get first element | FIRST_ELEMENT([1, 2, 3]) â 1 |
LAST_ELEMENT |
Get last element | LAST_ELEMENT([1, 2, 3]) â 3 |
APPEND |
Add element to end | APPEND([1, 2], 3) â [1, 2, 3] |
INDEX_OF |
Find position (0-based) | INDEX_OF(['a', 'b'], 'b') â 1 |
SET |
Remove duplicates | SET([1, 1, 2]) â [1, 2] |
FLATTEN |
Flatten one level | FLATTEN([[1], [2]]) â [1, 2] |
UNION(list1, list2) |
Combine unique elements | UNION([1, 2], [2, 3]) â [1, 2, 3] |
INTERSECTION |
Common elements | INTERSECTION([1, 2], [2, 3]) â [2] |
SET_DIFFERENCE |
Elements in list1 not in list2 | SET_DIFFERENCE([1, 2], [2, 3]) â [1] |
SUM |
Sum of numbers | SUM([1, 2, 3]) â 6 |
AVG |
Average of numbers | AVG([1, 2, 3]) â 2 |
MIN |
Minimum value | MIN([3, 1, 2]) â 1 |
MAX |
Maximum value | MAX([3, 1, 2]) â 3 |
CONCAT |
Join all strings | CONCAT(['a', 'b']) â "ab" |
JOIN |
Join with separator | JOIN(['a', 'b'], '-') â "a-b" |
MAP |
Transform each element | MAP([1, 2], x => x * 2) â [2, 4] |
FILTER |
Keep matching elements | FILTER([1, 2, 3], x => x > 1) â [2, 3] |
ALL |
All values true? | ALL([true, true, false]) â False |
ANY |
Any value true? | ANY([true, true, false]) â True |
SOME |
Any value true? (alias for ANY) |
SOME([true, false]) â True |
CUSTOM_MAX |
Max element ranked by an ordering list | CUSTOM_MAX([red, green], [green, red]) â red |
Checking List Contents¶
fruits = ['apple', 'banana']
fruits contains 'apple' # True
fruits contains any ['apple', 'pear'] # True
fruits contains only ['apple', 'banana'] # True
'apple' in fruits # True
'pear' not in fruits # True