Skip to content

Reducer

Dan Stocker edited this page Jun 1, 2019 · 2 revisions

Usage: createReducer<I, O>(cb: (curr: O, next: I, tag?: Tag) => O, initial?: O)

Module: flowcode-fp

Type: Reducer<I, O>

Input ports:

  • all: {d_val: I, a_flush: boolean}
  • d_val: I
  • a_flush: boolean

Output ports:

  • b_all: {d_val: I, a_flush: boolean}
  • b_d_val: I
  • d_val: O
  • ev_err: string

Aggregates input values between reset signals, according to an aggregator (reduce) callback. Operates in either independent or joined mode. Bounces input, and emits stringified error when callback throws.

import {connect} from "flowcode";
import {createReducer} from "flowcode-fp";
const reducer = createReducer((curr, next) => curr + next);
connect(reducer.o.d_val, console.log);
reducer.i.d_val(2);
reducer.i.d_val(3);
reducer.i.d_val(4);
reducer.i.a_flush(true); // logs: 9

Clone this wiki locally