Package: effect
Module: Array
Folds an iterable from left to right into a single value.
When to use
Use to combine all elements into one accumulated value from left to right.
Details
The function receives (accumulator, element, index).
Example (Summing an array)
import { Array } from "effect"
console.log(Array.reduce([1, 2, 3], 0, (acc, n) => acc + n)) // 6
See
reduceRight — fold from right to leftscan — fold keeping intermediate valuesSignature
declare const reduce: { <B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B; <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B; }
Since v2.0.0