$$sum
Returns a sum of all values in the array
Usage​
{
"$$sum": [ /* values */ ],
"by": /* Transformer */
"default": /* 0 */
}
"$$sum([default],[by]):{input}"
Returns​
BigDecimal
Arguments​
Argument | Type | Values | Required / Default Value | Description |
---|---|---|---|---|
Primary | array | Yes | Array to sum | |
default | BigDecimal | 0 | The default value to use for empty values | |
by | Transformer(##current ) | Input is ##current (current element) | "##current" | A transformer to extract a property to sum by (using ##current to refer to the current item) |
Examples​
Input
Definition
Output
[4, 2, 13.45, null]
"$$sum:$"
19.45
[4, 2, 13.45, null]
"$$sum(1):$"
20.45
[
{ "value": 4 },
{ "value": 2 },
{ "value": 13.45 },
{ "value": null }
]
{
"$$sum": "$",
"by": "##current.value"
}
19.45
[
{ "value": 4 },
{ "value": 2 },
{ "value": 13.45 },
{ "value": null }
]
{
"$$sum": "$",
"by": "##current.value",
"default": 1
}
20.45