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 31 32 33 34 | 7x 1x 7x 8x | import { Predicate } from "./_types";
/**
* Combines {@link Predicate}s with a logical `AND`.
*
* The combined {@link Predicate} returns `true` if all of the
* {@link Predicate}s returns `true`.
*
* @example
* Combine two Predicates with a logical `AND`
* ```
* const predicate = and(numberIsPositive, numberIsEven);
* const result = p(2);
* console.log(result); // true
* ```
*
* @example
* Returns an {@link alwaysTrue} Predicate if no args provided
* ```
* const predicate = and();
* const result = p();
* console.log(result); // true
* ```
*
* @typeParam T - the type of the {@link Predicate}s
* @param predicates - the {@link Predicate}s to combine
* @returns `true` if all {@link Predicate}s return `true`, otherwise `false`
*/
export const and =
<T extends unknown[]>(...predicates: Predicate<T>[]): Predicate<T> =>
(...args) => {
return predicates.every((predicate) => predicate(...args));
};
|