Skip to content

Reducers overview

Reducers are blocks that are placed immediately after loops to produce a summary output suitable to be transmitted downstream, possibly being the final output of a flow, thus they complement the contexts of splitters and remappers.
In other words, a reducer "takes out" the n outputs of a context—by itself isolated from the data flow—and uses them to produce a single JSON, it is like the "distiller" of a context.

For example, if the context of a splitter loops over multiple contracts to analyze them, n outputs are produced within the context, each reporting the outcome of the analysis for a contract. A reducer immediately downstream of the splitter's context produces a JSON containing an array of items, each of which may contain summary information taken the analysis output for a file. A per-item datum like the filename, can be inserted if each item of the array so to create the necessary mapping between the file and the corresponding output.

A reducer must always be placed after a context and it's not part of it, it's outside the context. This means that, unless the reducer itself is contained in an outer loop, it is executed only once per workflow's execution.