Map
This formula allows you to map each value of a list to a different value. For example, the following Map formula executed on the array [1, 2, 3] will result in the array [2, 3, 4]:
{
"type": "map",
"components": {
"type": "list",
"components": [
{
"type": "constant",
"value": 1,
"value_type": "integer"
},
{
"type": "constant",
"value": 2,
"value_type": "integer"
},
{
"type": "constant",
"value": 3,
"value_type": "integer"
},
]
},
"mapper": {
"type": "add",
"components": {
"type": "list",
"components": [
{
"type": "stat",
"stat": "$mapValue"
},
{
"type": "constant",
"value": 1,
"value_type": "integer"
},
]
}
}
}
JSON Format
{
"type": "map",
"components": ...,
"mapper": ...,
"map_value_key": ...
}
Fields
| Field | Type | Required | Description |
|---|---|---|---|
components | StatFormulaComponent | ✓ | The formula for the array (list) of elements you want to map. |
mapper | StatFormulaComponent | ✓ | The formula for the mapping to perform on each element of the given components list. Anything inside this formula can make use of the $mapValue stat, which will contain the current value for the iteration (e.g: if iterating the array ['a', 'b', 'c'], $mapValue will first be equal to 'a', then 'b' and then 'c'), thus allowing the formula specified here to access the value of each element in the array one at a time as part of the mapper. If you were to specify the optional map_value_key parameter, you should use the key given there instead of $mapValue to access these values. |
map_value_key | String | Optional parameter that lets you provide a key to use in the mapper formula to access the array's current value in the iteration. e.g: if you are iterating classes, you might want to assign "$class" to the map_value_key, to make your system easier to read. This is also helpful when dealing with nested Map formulas, as it will allow inner Map formulas to access the values of outer filter formulas. |