This page is part of a static HTML representation of the TiddlyWiki at https://tiddlywiki.com/

Reduce Filter Run Prefix

10th July 2023 at 7:33am
purposereplaces all filter output so far with a single item by repeatedly applying a filter run to each input title
inputthe filter output of all previous runs so far
outputthe accumulated single item
Introduced in v5.1.23
:reducerun

Each input title from previous runs is passed to this run in turn. The result of each previous call to this run is made available in the next call via the variable named accumulator. The result of the last call to this run is returned as the output. A typical use is to add up the values in a given field of each input title.

Replaces all filter output so far with a single item by repeatedly applying a formula, as described above, to each input title.

The following variables are available within the filter run:

  • accumulator - the result of the previous filter run
  • currentTiddler - the input title
  • ..currentTiddler - the value of the variable currentTiddler outside the filter run. Introduced in v5.2.0
  • index - the numeric index of the current list item (with zero being the first item in the list)
  • revIndex - the reverse numeric index of the current list item (with zero being the last item in the list)
  • length - the total length of the input list

Tip
Compare named filter run prefix :reduce with reduce Operator which is used to flatten a list of items down to a single item by repeatedly applying a subfilter.

[tag[shopping]] :reduce[get[quantity]add<accumulator>]

is equivalent to:

\define num-items() [get[quantity]add<accumulator>]

[tag[shopping]reduce<num-items>]

Reduce Filter Run Prefix (Examples)