MCPcopy Index your code
hub / github.com/refined-github/refined-github / pSomeFunction

Function pSomeFunction

source/helpers/p-utils.ts:25–52  ·  view source on GitHub ↗
(
	iterable: List,
	predicate: (value: Element) => Promisable<boolean>,
)

Source from the content-addressed store, hash-verified

23}
24
25export function pSomeFunction<
26 List extends Iterable<unknown>,
27 Element extends IterableElement<List>,
28>(
29 iterable: List,
30 predicate: (value: Element) => Promisable<boolean>,
31): Promisable<boolean> {
32 const promises: Array<PromiseLike<boolean>> = [];
33 // Prioritize sync functions and early returns
34 for (const item of iterable) {
35 const result = predicate(item as Element);
36 if (typeof result === 'boolean') {
37 if (result) {
38 // Early sync return on the first truthy value
39 return true;
40 }
41 } else {
42 promises.push(result);
43 }
44 }
45
46 if (promises.length === 0) {
47 // Matches `[].some(Boolean)`
48 return false;
49 }
50
51 return pSome(promises);
52}
53
54export function pEveryFunction<
55 List extends Iterable<unknown>,

Callers 1

shouldFeatureRunFunction · 0.85

Calls 1

pSomeFunction · 0.85

Tested by

no test coverage detected