Skip to main content

Function: and()

and<T>(...predicates): Predicate<T>

Defined in: predicate/combinators/index.ts:47

Combines multiple predicates with logical AND.

Returns a predicate that is true only if all predicates return true. Short-circuits on the first false result.

Type Parameters

T

T

Parameters

predicates

...Predicate<T>[]

The predicates to combine

Returns

Predicate<T>

A predicate that returns true if all predicates return true

Example

import * as R from 'remeda'
import { gt, lt, and } from 'receta/predicate'

// Combine comparisons
const numbers = [1, 5, 10, 15, 20]
R.filter(numbers, and(gt(5), lt(15))) // => [10]

// Multiple conditions
const users = [
{ age: 25, active: true, verified: true },
{ age: 30, active: false, verified: true },
{ age: 35, active: true, verified: false }
]
R.filter(
users,
and(
(u) => u.age >= 25,
(u) => u.active,
(u) => u.verified
)
) // => [{ age: 25, active: true, verified: true }]

See

  • or - for logical OR
  • not - for logical NOT