import { Reducer } from "https://deno.land/x/rimbu@0.13.1/common/internal.ts";
const { create } = Reducer;
Returns a Reducer
with the given options:
Examples
Example 1
Example 1
const evenNumberOfOnes = Reducer
.create(
true,
(current, value: number) => value === 1 ? !current : current,
state => state ? 'even' : 'not even')
const result = Stream.of(1, 2, 3, 2, 1)).reduce(evenNumberOfOnes)
console.log+(result)
// => 'even'
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