-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall.ts
30 lines (21 loc) · 797 Bytes
/
all.ts
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
import { getLogger } from '../logger.ts';
import { PredicateFn } from '../types/functions/mod.ts';
import { _curry } from '../lib/utils/mod.ts';
const logger = await getLogger('methods/all');
async function _all_impl_fn<T>(fn: PredicateFn<T>, iter: AsyncIterable<T>): Promise<boolean> {
logger.trace('all()');
for await (const elem of iter) {
const condition = await fn(elem);
logger.debug('element =', elem);
logger.debug('condition =', condition);
if (!condition) {
return false;
}
}
return true;
}
export interface All {
<T>(fn: PredicateFn<T>, iter: AsyncIterable<T>): Promise<boolean>;
<T>(fn: PredicateFn<T>): (iter: AsyncIterable<T>) => Promise<boolean>;
}
export const all: All = _curry(_all_impl_fn);