Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
{div:class=} h1.
Wiki Markup
Div
classapi-page

fluid.accumulate(list,

fn,

arg)

{section} {column:width=70%} 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 {code:javascript}

Section
Column
width70%

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

Code Block
javascript
javascript

fluid.accumulate(list, fn, arg);
{code} *

File

name:

* {{

Fluid.js

}} h2. Parameters {span:class=

Parameters

Span
classborderless-table

} |*{{list}}*|

list

(Array)

The

list

of

objects

to

be

accumulated

over.

| |*{{fn}}*|

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}}*|

arg

(Object)

The

initial

value

for

the

"running

total"

object.

| {span} h2. Return Value {span:class=borderless-table} |*Object*| The modified {{arg}} object. | {span} {column} {column:width=5%} {column} {column} h3. See Also {column} {section} ---- h3. Notes To a Google developer, this would be "reduce", from the

Return Value

Span
classborderless-table

Object

The modified arg object.

Column
width5%

Column

See Also


Notes

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

pairing.

h3. Example {code:javascript}

Example

Code Block
javascript
javascript

var func = function (column, list) {
    return list.concat(column.elements);
};
var modules = fluid.accumulate(layout.columns, func, [])
{code}

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.

{div}