deno.land / x / rambda@v9.1.1 / source / findAsync.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
import { isArray } from './_internals/isArray.js'import { mapAsync } from './mapAsync.js'
export function findAsyncFn(predicate, list){ return new Promise((resolve, reject) => { let canContinue = true let found
const predicateFn = async (x, i) => { if (!canContinue) return false try { const result = await predicate(x, i) if (result){ canContinue = false found = x } } catch (error){ reject(error) } }
mapAsync(predicateFn, list) .then(() => resolve(found)) .catch(reject) })}
export function findAsync(predicate, list){ if (arguments.length === 1){ return async _list => findAsync(predicate, _list) }
return new Promise((resolve, reject) => { findAsyncFn(predicate, list).then(resolve) .catch(reject) })}
rambda

Version Info

Tagged at
2 months ago