effect-io-ai

Package: effect
Module: Predicate

Predicate.and

Creates a predicate that returns true only if both predicates are true.

When to use

Use when you want to combine Predicates with AND, accepting values that satisfy multiple conditions, including refinements that narrow to an intersection.

Details

Evaluation short-circuits on the first false. For refinements, the output type is an intersection.

Example (Checking both conditions)

import { Predicate } from "effect"

const hasAAndB = Predicate.and(
  Predicate.hasProperty("a"),
  Predicate.hasProperty("b")
)

const input: unknown = JSON.parse(`{"a":1,"b":"ok"}`)
if (hasAAndB(input)) {
  // input has both properties at this point
  const a = input.a
  const b = input.b
}

See

Signature

declare const and: { <A, C extends A>(that: Refinement<A, C>): <B extends A>(self: Refinement<A, B>) => Refinement<A, B & C>; <A, B extends A, C extends A>(self: Refinement<A, B>, that: Refinement<A, C>): Refinement<A, B & C>; <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>; <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>; }

Source

Since v2.0.0