Skip to main content
Module

x/rimbu/mod.ts>Reducer.createOutput

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
function Reducer.createOutput
import { Reducer } from "https://deno.land/x/rimbu@0.14.0/mod.ts";
const { createOutput } = Reducer;

Returns a Reducer of which the state and output types are the same.

Examples

Example 1

const boolToString = Reducer
  .createOutput(
    '',
    (current, value: boolean) => current + (value ? 'T' : 'F')
  )
const result = Stream.of(true, false, true)).reduce(boolToString)
console.log+(result)
// => 'TFT'

Type Parameters

I
optional
O = I

Parameters

init: OptLazy<O>
  • the initial state value
next: (
current: O,
next: I,
index: number,
halt: () => void,
) => O
  • 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
optional
stateToResult: (state: O) => O
  • (optional) a function that converts the current state to an output value