Skip to main content

overEvery()

overEvery<T>(predicates): (value) => boolean

Creates a function that checks if all of the predicates return truthy when invoked with the arguments it receives.

DEPRECATED

Use predicates.every(fn => fn(value)) directly instead.


Type Parametersโ€‹

T: Tโ€‹

The type of the value to check.


Parametersโ€‹

predicates: (value) => boolean[]โ€‹

The predicates to check.


Returnsโ€‹

A function that returns true if all predicates pass.


See Alsoโ€‹

Array.every() - MDN


Sinceโ€‹

2.0.0


Also known asโ€‹

allPass (Ramda) ยท overEvery (Lodash, es-toolkit) ยท โŒ (Remeda, Radashi, Effect, Modern Dash, Antfu)


Exampleโ€‹

// โŒ Deprecated approach
const isPositiveEven = overEvery([n => n > 0, n => n % 2 === 0]);
isPositiveEven(4); // => true
isPositiveEven(-2); // => false

// โœ… Recommended approach
const predicates = [(n: number) => n > 0, (n: number) => n % 2 === 0];
const isPositiveEven = (n: number) => predicates.every(fn => fn(n));
isPositiveEven(4); // => true
isPositiveEven(-2); // => false

How it works?โ€‹

Creates a function that checks if all predicates return truthy. Deprecated: Use Array.every() with predicates.

Native Equivalentโ€‹

// โŒ overEvery([fn1, fn2])(value)
// โœ… [fn1, fn2].every(fn => fn(value))

Use Casesโ€‹

Combine predicates with AND ๐Ÿ“Œโ€‹

Check if all predicates pass.

const predicates = [
(n: number) => n > 0,
(n: number) => n % 2 === 0
];
const isPositiveEven = (n: number) => predicates.every(fn => fn(n));
isPositiveEven(4); // true
isPositiveEven(-2); // false

Validate multiple rulesโ€‹

Ensure value passes all validation rules.

const rules = [
(s: string) => s.length >= 8,
(s: string) => /[A-Z]/.test(s),
(s: string) => /[0-9]/.test(s)
];
const isValidPassword = (s: string) => rules.every(r => r(s));