List functions
- Applies to:
- All versions
- Role required:
- Draft Contributor
list.apply(list, expression) : list
Create a new list by applying the expression to each item.
| Name | Type | Description |
|---|---|---|
| list | list | list value |
| expression | str | expression to apply (use '$' to refer to the current item) |
list.average(list, expression) : num
Get the average of the values in a list.
| Name | Type | Description |
|---|---|---|
| list | list | list value |
| expression | str | (optional) expression to fetch value (use '$' to refer to the current item; default: $) |
list.collect(list, key) : list
Collect all values from each map inside the list.
| Name | Type | Description |
|---|---|---|
| list | list | list of maps |
| key | str | key for value to collect |
list.combine(keys, values) : map
Combine two lists into a map.
| Name | Type | Description |
|---|---|---|
| keys | list | list of keys |
| values | list | list of values |
list.contains(list, value, ignorecase) : bool
Check if a list contains the given value.
| Name | Type | Description |
|---|---|---|
| list | list | list value |
| value | any | value to check for |
| ignorecase | bool | (optional) ignore case (default: false) |
list.count(list, condition) : num
Count the number of items for which the condition succeeds.
| Name | Type | Description |
|---|---|---|
| list | list | list value |
| condition | str | condition to execute for each item (use '$' to refer to the item) |
list.groupby(list, expression) : map
Group items in a list by common expression value.
| Name | Type | Description |
|---|---|---|
| list | list | list value |
| expression | str | expression to apply for grouping (use '$' to refer to the current item) |
list.indexesof(list, value) : list
Find all index positions of the given value.
| Name | Type | Description |
|---|---|---|
| list | list | list value |
| value | any | value to check for |
list.indexof(list, value) : num
Find the index position of the given value.
| Name | Type | Description |
|---|---|---|
| list | list | list value |
| value | any | value to check for |
list.intersect(first, second, condition) : list
Compute the list of values that are common to the first and second list.
| Name | Type | Description |
|---|---|---|
| first | list | first list |
| second | list | second list |
Optional: Use the condition (str) expression to determine if an item from the first list should be included in the final list.
- Return true to include, false to exclude.
- Use
$leftand$rightto refer to the current item from the first and seconds lists, respectively. - Default: equality condition
list.lastindexof(list, value) : num
Find the last index position of the given value.
| Name | Type | Description |
|---|---|---|
| list | list | list value |
| value | any | value to check for |
list.max(list, expression) : num
Get the largest value in a list.
| Name | Type | Description |
|---|---|---|
| list | list | list value |
| expression | str | (optional) expression to fetch value (use $ to refer to the current item; default: $) |
list.min(list, expression) : num
Get the smallest value in a list.
| Name | Type | Description |
|---|---|---|
| list | list | list value |
| expression | str | (optional) expression to fetch value (use $ to refer to the current item; default: $) |
list.new(size, value) : list
Create a list of a given size.
| Name | Type | Description |
|---|---|---|
| size | num | size of the list |
| value | any | (optional) intial value for list entry (default: nil) |
list.orderby(list, keys) : list
Sort items in a list using key names.
| Name | Type | Description |
|---|---|---|
| list | list | list value |
| keys | any | key name or list of key names; sort direction is controlled by adding " ascending" or " descending" to the keys; when omitted, the direction is ascending by default |
list.random(list) : any
Get a random item from the list.
| Name | Type | Description |
|---|---|---|
| list | list | list value |
list.reduce(list, expression, value) : any
Combine all values in a list into a single value using the supplied expression.
| Name | Type | Description |
|---|---|---|
| list | list | list value |
| expression | str | expression to compute combined value (use '$value' and '$item' to refer to the current value and item, respectively) |
| value | any | (optional) starting value (default: nil) |
list.reverse(list) : list
Reverse the items in a list.
| Name | Type | Description |
|---|---|---|
| list | list | list value |
Example:
var lst = ["one","two","three","four","five"]; list.reverse(lst);
list.select(list, condition) : list
Create a list that only contains values for which the condition succeeds.
| Name | Type | Description |
|---|---|---|
| list | list | list value |
| condition | str | condition to execute for each item (use '$' to refer to the item) |
list.sort(list, key, reverse, compare) : list
Sort the items in a list.
| Name | Type | Description |
|---|---|---|
| list | list | list of values |
| key | any | (optional) key for value if list contains maps (default: nil) |
| reverse | bool | (optional) sort in reverse order (default: false) |
Optional:
- Use
compare(str) to compare two items. - Use
$leftand$rightto refer to the left and right items, respectively. - Return
-1if the left item is less than the right item;0if items are equal;+1if the left item is greater than the right item.
list.splice(list, start, length, values) : list
Split a list and insert new items into it.
| Name | Type | Description |
|---|---|---|
| list | list | list value |
| start | num | copy all values before the start offset; if negative, offset is relative to end of list |
| length | num | (optional) number of elements to skip; if negative, relative to length of list (default: all) |
| values | list | (optional) values to append after start offset (default: none) |
Example:
var lst = ["one","two","three","four","five"]; list.splice(lst,2);
list.sum(list, expression) : num
Get the sum of values in a list.
| Name | Type | Description |
|---|---|---|
| list | list | list value |
| expression | str | (optional) expression to fetch value (use $ to refer to the current item; default: $) |
