deno.land / x / rambda@v9.1.1 / source / reduce.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { isArray } from './_internals/isArray.js'import { curry } from './curry.js'
class ReduceStopper{ constructor(value){ this.value = value }}
export function reduceFn( reducer, acc, list){ if (list == null){ return acc } if (!isArray(list)){ throw new TypeError('reduce: list must be array or iterable') } let index = 0 const len = list.length
while (index < len){ acc = reducer( acc, list[ index ], index, list ) if (acc instanceof ReduceStopper){ return acc.value } index++ }
return acc}
export const reduce = curry(reduceFn)export const reduceStopper = value => new ReduceStopper(value)
rambda

Version Info

Tagged at
2 months ago