Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 17x 4x 17x 17x 16x 5x 12x | import { Predicate } from "@benneq/predicate";
/**
* Checks if any element of an {@link Iterable} matches a {@link Predicate}.
*
* @example
* Is any value even?
* ```ts
* const anyValueEven = some(x => x % 2);
* const result = anyValueEven([1,2,3]);
* console.log(result); // true
* ```
*
* @see {@link every} and {@link filter} for similar operations.
*
* @typeParam T - the {@link Iterable} value type
* @param predicate - the {@link Predicate} to match
* @returns `true` if the {@link Predicate} returns `true` for any element
*/
export const some =
<T>(predicate: Predicate<[T]>) =>
(iterable: Iterable<T>): boolean => {
for (const value of iterable) {
if (predicate(value)) {
return true;
}
}
return false;
};
|