-
Notifications
You must be signed in to change notification settings - Fork 0
/
some.ts
29 lines (28 loc) · 955 Bytes
/
some.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
import { deferP0 } from "ts-functional-pipe";
import { IndexedPredicate } from "../types/IndexedPredicate";
/**
* returns `true` if *any* elements in `src` return `true` when passed to `pred`
* @remarks does not enumerate further if `pred` returns `false` on a value
* @param src source sequence
* @param pred indexed predicate function
*/
export function _some<T>(
src: Iterable<T>,
pred: IndexedPredicate<T> = (_) => true
): boolean {
let i = 0;
for (const item of src) {
if (pred(item, i++)) {
return true;
}
}
return false;
}
/**
* returns `true` if *any* elements in `src` return `true` when passed to `pred`
* @remarks does not enumerate further if `pred` returns `false` on a value
* {@link https://biggyspender.github.io/ts-functional-pipe/globals.html#deferp0 P0 deferred} version of {@link _every}
* @param src source sequence
* @param pred indexed predicate function
*/
export const some = deferP0(_some);