Skip to main content
Module

x/ramda/mod.ts>transduce

:ram: Practical functional Javascript
Latest
variable transduce
import { transduce } from "https://deno.land/x/ramda@v0.27.2/mod.ts";

Initializes a transducer using supplied iterator function. Returns a single item by iterating through the list, successively calling the transformed iterator function and passing it an accumulator value and the current value from the array, and then passing the result to the next call.

The iterator function receives two values: (acc, value). It will be wrapped as a transformer to initialize the transducer. A transformer can be passed directly in place of an iterator function. In both cases, iteration may be stopped early with the R.reduced function.

A transducer is a function that accepts a transformer and returns a transformer and can be composed directly.

A transformer is an object that provides a 2-arity reducing iterator function, step, 0-arity initial value function, init, and 1-arity result extraction function, result. The step function is used as the iterator function in reduce. The result function is used to convert the final accumulator into the return type and in most cases is R.identity. The init function can be used to provide an initial accumulator, but is ignored by transduce.

The iteration is performed with R.reduce after initializing the transducer.