Hyperlinkv0.8.0-beta.28

Predicate

Predicate.everyfunctioneffect/Predicate.ts:1825
<A>(collection: Iterable<Predicate<A>>): Predicate<A>

Creates a predicate that returns true if all predicates in the collection return true.

When to use

Use when you have a dynamic list of predicates to apply.

Details

Evaluation short-circuits on the first false. The collection is iterated each time the predicate is called.

Example (Checking all predicates)

import { Predicate } from "effect"

const allChecks = Predicate.every([Predicate.isNumber, (n: number) => n > 0])

console.log(allChecks(2))
elementssomeand
export function every<A>(collection: Iterable<Predicate<A>>): Predicate<A> {
  return (a) => {
    for (const p of collection) {
      if (!p(a)) {
        return false
      }
    }
    return true
  }
}