-
Notifications
You must be signed in to change notification settings - Fork 2
System.Reduce
Dennis G. edited this page Sep 1, 2024
·
3 revisions
function Reduce(Values: System.Struct, Reducer: function, Initial = System.Null) = \built-in\
The Reduce function in the System package reduces an existing structure (array or record) to a single value.
The second parameter is a function with two parameters. When the function is called, System.Length(Values) iterations are done through the structure and the accumulator plus value for each element/field is passed as argument to Reducer. The reducer function shall return a value that replaces the whole structure that is then either passed to the next iteration or returned as function result.
- The function result is the result from the final call of
Reducer. -
Reduceris called with the accumulator (orInitialparameter in the first run) as first and with the current element/field value as second argument. - If the length of
Valuesis zero,Reduceris never called andInitialis returned. - If
Reducerdemands more or less arguments than2, an exception is raised.
Texts, images and code samples on this page are available under MPL 2.0 license