Hyperlinkv0.8.0-beta.28

Predicate

Predicate.somefunctioneffect/Predicate.ts:1863
<A>(collection: Iterable<Predicate<A>>): Predicate<A>

Creates a predicate that returns true if any predicate in the collection returns true.

When to use

Use when you have a dynamic list of predicates and only need one to pass.

Details

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

Example (Checking any predicate)

import { Predicate } from "effect"

const anyCheck = Predicate.some([Predicate.isString, Predicate.isNumber])

console.log(anyCheck("ok"))
elementseveryor
export function some<A>(collection: Iterable<Predicate<A>>): Predicate<A> {
  return (a) => {
    for (const p of collection) {
      if (p(a)) {
        return true
      }
    }
    return false
  }
}