import { Reducer } from "https://deno.land/x/rimbu@0.13.0/common/index.ts";
const { createMono } = Reducer;
Returns a Reducer
of which the input, state, and output types are the same.
Examples
Example 1
Example 1
const sum = Reducer
.createMono(
0,
(current, value) => current + value
)
const result = Stream.of(1, 2, 3, 2, 1)).reduce(sum)
console.log+(result)
// => 9
Parameters
- returns the next state value based on the given inputs:
- current: the current state
- next: the current input value
- index: the input index value
- halt: function that, when called, ensures no more elements are passed to the reducer