System.Reduce - Manhunter07/MFL GitHub Wiki

Declaration

function Reduce(Values: System.Struct, Reducer: function, Initial = System.Null) = \built-in\

Description

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.

Remarks

  • The function result is the result from the final call of Reducer.
  • Reducer is called with the accumulator (or Initial parameter in the first run) as first and with the current element/field value as second argument.
  • If the length of Values is zero, Reducer is never called and Initial is returned.
  • If Reducer demands more or less arguments than 2, an exception is raised.

See also