View this page in the latest version of Appian. reduce() Function Share Share via LinkedIn Reddit Email Copy Link Print On This Page Calls a rule or function for each item in a list, passing the result of each call to the next one, and returns the value of the last computation. Parameters reduce( function, initial, list, context ) Keyword Type Description function Rule or Function Reference Rule or expression function. initial Any Type The accumulator's initial value. list Any Type Array of elements that the function iterates through. context Any Type Array Variable number of parameters passed directly into each function evaluation. Returns Any Type Using the function The following sections cover important details about the reduce() function. When to use reduce() The reduce() function is best used when the computation of each operation needs to use the result from the previous operation such as when the result of each operation is an array that should be appended to each other in order. The result from the previous operation is then passed to the subsequent operation as the parameter initial. Passing arguments The reduce() function's parameters are positional and do not support keyword syntax. Using keyword syntax like reduce(function: fn!substitute, ...) causes an error. Using the function parameter In the function parameter of reduce(), enter fn!functionName or a!functionName to reference an expression function, or rule!ruleName to reference a rule. The initial accumulator value is given by the initial parameter. Using rules or functions with multiple arguments To use rules or functions that take more than two arguments, use the merge() function. For example, given a rule g(x, y, z), reduce(rule!g, i, merge({a, b, c}, {d, e, f})) returns g(g(g(i, a, d), b, e), c, f). Understanding results Returns a scalar value if the function called returns a scalar, and returns a list if the function called returns a list. Unsupported functions The reduce() function doesn't support a!forEach() in rules that you use as the function. Examples The following examples demonstrate the reduce() function. To experiment with examples, copy and paste the expression into an expression rule and click TEST RULE to see the output. Substitute multiple values from initialValue This example substitutes characters from a string one at a time, passing the result of each substitution to the next. 1 2 3 4 5 6 reduce( fn!substitute, "abcdefg", {"a", "d", "f"}, "#" ) Returns "#bc#e#g". The function first replaces "a" from the initialValue. Then "d" is replaced from the result of the previous substitution. Finally, "f" is replaced. Create new list from initial value This example inserts values into a list one at a time, building a new list from an initial value. 1 2 3 4 5 6 reduce( fn!insert, {1}, {2, 3}, 1 ) Returns {3, 2, 1}. The function firsts inserts 2 at the first position and then inserts 3 into the first position of the resulting list from the first insert. Feature compatibility The table below lists this function's compatibility with various features in Appian. Feature Compatibility Note Portals Compatible Offline Interfaces Compatible Sync-Time Custom Record Fields Compatible Can be used to create a custom record field that only evaluates at sync time. Real-Time Custom Record Fields Incompatible Custom record fields that evaluate in real time must be configured using one or more Custom Field functions. Process Reports Incompatible Cannot be used to configure a process report. Process Events Partially compatible If autoscale is enabled, can be used to configure a supported process event node (such as a start event or timer event). Process Autoscaling Compatible Can be used in autoscaled processes. Event Consumer Filter Conditions Compatible Can be used in filter conditions. Event Consumer Event Handlers Compatible Can be used in event handler expressions. Feedback Was this page helpful? SHARE FEEDBACK Loading...