1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-03 18:53:28 +00:00
TiddlyWiki5/editions/tw5.com/tiddlers/filters/syntax/Reduce Filter Run Prefix.tid
btheado 2f86779a27
Add doc tiddlers for reduce filter run prefix functionality (#6277)
* Added documentation tiddlers for reduce filter run prefix

* Make filter text box wider so long filters fit better

* removed some duplicate words

* Restored the :reduce filter run prefix tip
2021-11-24 20:02:40 +00:00

38 lines
1.6 KiB
Plaintext

created: 20211124151912931
modified: 20211124170117511
tags: [[Filter Syntax]] [[Filter Run Prefix]]
title: Reduce Filter Run Prefix
type: text/vnd.tiddlywiki
<<.from-version "5.1.23">>
|''purpose'' |replaces all filter output so far with a single item by repeatedly applying a filter run to each input title |
|''input'' |all titles from previous filter runs |
|''output''|the accumulated single item |
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.
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. <<.from-version "5.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>]
```
[[Examples|Reduce Filter Run Prefix (Examples)]]