Options
All
  • Public
  • Public/Protected
  • All
Menu

Module array/reduceWhile

Index

References

Type aliases

Functions

References

Renames and re-exports reduceWhile

Type aliases

ReducePred<T, R>: (acc: R, elem: T, index: number, arr: ArrayLike<T>) => boolean

Type parameters

  • T

  • R

Type declaration

    • (acc: R, elem: T, index: number, arr: ArrayLike<T>): boolean
    • Parameters

      • acc: R
      • elem: T
      • index: number
      • arr: ArrayLike<T>

      Returns boolean

Functions

  • Returns a single item by iterating through the list, successively calling the iterable function. reduceWhile also takes a predicate that is evaluated before each step. If the predicate returns false, it "short-circuits" the iteration and returns the current value of the accumulator.

    Note: if arr is undefined or null, acc will be returned by reference immediately

    example
     reduceWhile(acc => acc.length < 3, (acc, x) => acc + x, '1', ['2', '3', '4', '5']) // '123'
    

    Type parameters

    • T

    • R

    Parameters

    • predicate: ReducePred<T, R>
    • fn: ReduceFunc<T, R>

      The iterable function. Receives four values, the accumulator, the current element from the array, its index, and the original array.

    • acc: R

      The accumulator value.

    • list: ArrayLike<T>

    Returns R

    The final, accumulated value.

  • Returns a single item by iterating through the list, successively calling the iterable function. reduceWhile also takes a predicate that is evaluated before each step. If the predicate returns false, it "short-circuits" the iteration and returns the current value of the accumulator.

    Note: if arr is undefined or null, acc will be returned by reference immediately

    example
     reduceWhile(acc => acc.length < 3, (acc, x) => acc + x, '1', ['2', '3', '4', '5']) // '123'
    

    Type parameters

    • T

    • R

    Parameters

    • predicate: ReducePred<T, R>
    • fn: ReduceFunc<T, R>

      The iterable function. Receives four values, the accumulator, the current element from the array, its index, and the original array.

    • acc: R

      The accumulator value.

    Returns (list: ArrayLike<T>) => R

    The final, accumulated value.

      • (list: ArrayLike<T>): R
      • Parameters

        • list: ArrayLike<T>

        Returns R

  • Returns a single item by iterating through the list, successively calling the iterable function. reduceWhile also takes a predicate that is evaluated before each step. If the predicate returns false, it "short-circuits" the iteration and returns the current value of the accumulator.

    Note: if arr is undefined or null, acc will be returned by reference immediately

    example
     reduceWhile(acc => acc.length < 3, (acc, x) => acc + x, '1', ['2', '3', '4', '5']) // '123'
    

    Type parameters

    • T

    • R

    Parameters

    • predicate: ReducePred<T, R>
    • fn: ReduceFunc<T, R>

      The iterable function. Receives four values, the accumulator, the current element from the array, its index, and the original array.

    Returns CurriedFunction2<R, ArrayLike<T>, R>

    The final, accumulated value.

  • Returns a single item by iterating through the list, successively calling the iterable function. reduceWhile also takes a predicate that is evaluated before each step. If the predicate returns false, it "short-circuits" the iteration and returns the current value of the accumulator.

    Note: if arr is undefined or null, acc will be returned by reference immediately

    example
     reduceWhile(acc => acc.length < 3, (acc, x) => acc + x, '1', ['2', '3', '4', '5']) // '123'
    

    Type parameters

    • T

    • R

    Parameters

    Returns CurriedFunction3<ReduceFunc<T, R>, R, ArrayLike<T>, R>

    The final, accumulated value.

Generated using TypeDoc