Class ReduceFunction
java.lang.Object
com.api.jsonata4java.expressions.functions.FunctionBase
com.api.jsonata4java.expressions.functions.ReduceFunction
From http://docs.jsonata.org/higher-order-functions#reduce
Signature: $reduce(array, function [, init])
Returns an aggregated value derived from applying the function parameter
successively to each value in array in combination with the result of the
previous application of the function.
The function must accept at least two arguments, and behaves like an infix
operator between each value within the array. The signature of this supplied
function must be of the form:
myfunc($accumulator, $value[, $index[, $array]])
Example
( $product := function($i, $j){$i * $j}; $reduce([1..5], $product) ) This
multiplies all the values together in the array [1..5] to return 120.
If the optional init parameter is supplied, then that value is used as the
initial value in the aggregation (fold) process. If not supplied, the initial
value is the first value in the array parameter.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.api.jsonata4java.expressions.functions.FunctionBase
FunctionBase.CtxEvalResult -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddObject(com.fasterxml.jackson.databind.node.ArrayNode result, com.fasterxml.jackson.databind.node.ObjectNode obj) intintcom.fasterxml.jackson.databind.JsonNodeinvoke(ExpressionsVisitor expressionVisitor, MappingExpressionParser.Function_callContext ctx) Methods inherited from class com.api.jsonata4java.expressions.functions.FunctionBase
evalContext, getArgumentCount, getFunctionName
-
Field Details
-
ERR_BAD_CONTEXT
-
ERR_ARG1BADTYPE
-
ERR_ARG2BADTYPE
-
ERR_ARG1_MUST_BE_ARRAY_OF_OBJECTS
-
-
Constructor Details
-
ReduceFunction
public ReduceFunction()
-
-
Method Details
-
invoke
public com.fasterxml.jackson.databind.JsonNode invoke(ExpressionsVisitor expressionVisitor, MappingExpressionParser.Function_callContext ctx) - Specified by:
invokein classFunctionBase
-
getMaxArgs
public int getMaxArgs()- Specified by:
getMaxArgsin classFunctionBase
-
getMinArgs
public int getMinArgs()- Specified by:
getMinArgsin classFunctionBase
-
getSignature
- Specified by:
getSignaturein classFunctionBase
-
addObject
public void addObject(com.fasterxml.jackson.databind.node.ArrayNode result, com.fasterxml.jackson.databind.node.ObjectNode obj)
-