Skip to main content

reduce()

reduce<T, R>(fn): (initVal) => (arr) => R

Calls the accumulator with each element of the given array, starting with the first element. Returns the final result.

Type Parameters

T

T

The type of array elements.

R

R

The result type of the folder function.

Parameters

fn

Accumulator<T, R>

The accumulator function to apply to each element of the array.

Returns

(initVal): (arr) => R

Parameters

initVal

R

Returns

(arr): R

Parameters

arr

T[]

Returns

R

Remarks

pure function

Example

import { reduce } from '@accelint/core';

reduce((total, n) => total + n)(0)([1, 2, 3, 4, 5]);
// 15