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

partitionAsync.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
38
39
40
41
42
43
44
import { isArray } from './_internals/isArray.js'
async function whenObject(predicate, input){ const yes = {} const no = {} Object.entries(input).forEach(([ prop, value ]) => { if (predicate(value, prop)){ yes[ prop ] = value } else { no[ prop ] = value } })
return [ yes, no ]}
async function partitionAsyncFn(predicate, input){ if (!isArray(input)) return whenObject(predicate, input)
const yes = [] const no = [] for (const i in input){ const predicateResult = await predicate(input[ i ], Number(i)) if (predicateResult){ yes.push(input[ i ]) } else { no.push(input[ i ]) } }
return [ yes, no ]}
export function partitionAsync(predicate, list){ if (arguments.length === 1){ return async _list => partitionAsyncFn(predicate, _list) }
return new Promise((resolve, reject) => { partitionAsyncFn(predicate, list).then(resolve) .catch(reject) })}
rambda

Version Info

Tagged at
2 months ago