and() function creates a higher-order guard that evaluates to true only if all guards passed to it evaluate to true.
Signature
Parameters
An array of guards to evaluate. Each guard can be:
- A named guard string (e.g.,
'isValid') - A guard object with
typeand optionalparams - An inline guard function
Returns
A guard that returnstrue if all provided guards evaluate to true, otherwise false.
Usage
Basic Example
Mixing Named and Inline Guards
With Guard Parameters
Nested Composition
Behavior
- Short-circuit evaluation: If any guard returns
false, remaining guards are not evaluated - Empty array: An empty array is treated as
true(all zero guards passed) - Order matters: Guards are evaluated left-to-right until one returns
false
Type Safety
Theand() function maintains type safety across all guards:
See Also
- or - Logical OR for guards
- not - Logical NOT for guards
- Guards Overview - Introduction to guards