Hyperlinkv0.8.0-beta.28

Predicate

Predicate.impliesconsteffect/Predicate.ts:1722
<A>(consequent: Predicate<A>): (antecedent: Predicate<A>) => Predicate<A>
<A>(antecedent: Predicate<A>, consequent: Predicate<A>): Predicate<A>

Creates a predicate representing logical implication: if antecedent, then consequent.

When to use

Use when you need to encode logical implication between Predicate rules, where one rule only applies when a precondition holds.

Details

Models constraints like "if A then B" and returns true when the antecedent is false.

Example (Checking implication)

import { Predicate } from "effect"

const isAdult = (age: number) => age >= 18
const canVote = (age: number) => age >= 18
const implies = Predicate.implies(isAdult, canVote)

console.log(implies(16))
combinatorsandor
export const implies: {
  <A>(consequent: Predicate<A>): (antecedent: Predicate<A>) => Predicate<A>
  <A>(antecedent: Predicate<A>, consequent: Predicate<A>): Predicate<A>
} = dual(
  2,
  <A>(antecedent: Predicate<A>, consequent: Predicate<A>): Predicate<A> => (a) => antecedent(a) ? consequent(a) : true
)