QueryReduce
This function reduces the query to a single value.
Method Signature
QueryReduce(query=[query], callback=[function:BiFunction], initialValue=[any])Arguments
Argument
Type
Required
Description
Default
query
query
true
The query to iterate over
callback
function:BiFunction
true
The function to invoke for each item. The function will be passed 4 arguments: the accumulator, the current item, the current index, and the query. You can alternatively pass a Java Predicate which will only receive the first 2 args.
initialValue
any
true
The initial value to use for the reduction
Examples
Reduce column to total
Sum one query column
fruits = queryNew( "fruit,amount", "varchar,integer", [
{
"fruit" : "apples",
"amount" : 15
},
{
"fruit" : "pineapples",
"amount" : 3
},
{
"fruit" : "strawberries",
"amount" : 32
}
] );
total_fruits = queryReduce( fruits, ( Any a, Any b ) => {
return a + b.AMOUNT;
}, 0 );
writeOutput( total_fruits );
Result: 50
Additional Examples
Related
Last updated
Was this helpful?
