import { ArrayAccumulator, MapAccumulator, ObjectAccumulator, SetAccumulator, StringAccumulator } from './src/types' /** * @description * Universal version of native `Array#reduce` that works on pretty much any * iterable - arrays & array-likes, objects, Sets, Maps, strings, custom * iterables, etc. * * @parameters * | name | type | description | * | :--: | :--: | ----------- | * | collection | `Iterable` | Iterable-like object to reduce from | * | fn | `Function` | Function that builds the accumulator with each iteration | * | initial | `any` | Value first passed to `fn` | * * @returns `any` * * @example * let collection = { one: 1, two: 2, three: 3 } * reduce(collection, (acc, cur) => acc + cur, 0) * // -> 6 * * collection = [1, 2, 3, 4, 5] * reduce(collection, (acc, cur) => acc + cur, 0) * // -> 15 * * collection = 'foobar' * fn(collection, (acc, cur) => { * acc.splice(0, 0, cur) * return acc * }, []) * // -> ['r', 'a', 'b', 'o', 'o', 'f'] * * @see reduceWhile * @since v1.0.0 * @tag collections */ interface Reduce { (collection: T, fn: StringAccumulator, initial?: U): U (collection: T[], fn: ArrayAccumulator, initial?: U): U (collection: Map, fn: MapAccumulator): Map (collection: Set, fn: SetAccumulator, initial?: U): U (collection: T, fn: ObjectAccumulator): T (collection: T, fn: ObjectAccumulator, initial: U): U } declare const reduce: Reduce export = reduce