import { ArrayAccumulator, MapAccumulator, ObjectAccumulator, SetAccumulator, StringAccumulator } from './src/types' /** * @description * Works just like [`reduce`](#reduce) but short-circuits when * `predicate` returns a falsy value. * * @parameters * | name | type | description | * | :--: | :--: | ----------- | * | collection | `Iterable` | Iterable-like object to reduce from | * | predicate | `Function` | Function that will stop iteration when returning a falsy value | * | fn | `Function` | Function that builds the accumulator with each iteration | * | initial | `any` | Value first passed to `fn` | * * @returns `any` * * @example * const predicate = accumulator => accumulator !== 3 * const reducer = (acc, cur) => acc + cur * const object = { one: 1, two: 2, three: 3 } * * reduce(object, reducer, 0) * // -> 6 * * reduceWhile(object, predicate, reducer, 0) * // -> 3 * * @see reduce * @since v1.0.0 * @tag collections */ interface ReduceWhile { (collection: T, predicate: (accumulator: T, value: U) => boolean, fn: StringAccumulator, initial?: U): U (collection: T[], predicate: (accumulator: T[], value: U) => boolean, fn: ArrayAccumulator, initial?: U): U (collection: Map, predicate: (accumulator: Map, value: V) => boolean, fn: MapAccumulator): Map (collection: Set, predicate: (accumulator: Set, value: U) => boolean, fn: SetAccumulator, initial?: U): U (collection: T, predicate: (accumulator: T, value: T[keyof T]) => boolean, fn: ObjectAccumulator): T (collection: T, predicate: (accumulator: T, value: U) => boolean, fn: ObjectAccumulator, initial: U): U } declare const reduceWhile: ReduceWhile export = reduceWhile