$$sum
Returns the sum of all values in an array
Usage​
{
"$$sum": /* Array to sum */,
"default": 0 /* BigDecimal */,
"by": /* Transformer(##current) */
}
"$$sum([default],[by]):{input}"
note
Concrete values in the usage example are default values.
Returns​
number
(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 ) | null | A transformer to extract a property to sum by
|
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(1,##current.value):$"
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