Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Wiki Markup

h1. fluid.accumulate(list, fn, arg)
Scans through a list of objects, "accumulating" a value over them (may be a straightforward "sum" or some other chained computation). The results will be added to the initial value passed in by "arg" and returned
fluid.accumulate(list, fn, arg);
*File name:* {{Fluid.js}}

h2. Parameters

|*{{list}}*| (Array) The list of objects to be accumulated over. |
|*{{fn}}*| (Function) An "accumulation function" accepting the signature (object, total, index) where object is the list member, total is the "running total" object (which is the return value form the previous function), and index is the index number. |
|*{{arg}}*| (Object) The initial value for the "running total" object. |

h2. Return Value
|*Object*| The modified {{arg}} object. |



h3. See Also


h3. Notes

To a Google developer, this would be "reduce", from the "map/reduce" pairing.

h3. Example
var func = function (column, list) {
    return list.concat(column.elements);
var modules = fluid.accumulate(layout.columns, func, [])
In this example, the function {{func}} will add the {{elements}} property of each entry of {{list.columns}} to an initially empty array and return the filled array.