Skip to main content

$$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​

ArgumentTypeValuesRequired / Default ValueDescription
PrimaryarrayYesArray to sum
defaultBigDecimal0The default value to use for empty values
byTransformer(##current)nullA transformer to extract a property to sum by
  • ##current - Current element

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