Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rimbu/core/main/index.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.13.1/core/main/index.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