Logic
Predicate combinators
Section titled “Predicate combinators”both<A>(p1: (a: A) => boolean, p2: (a: A) => boolean): (a: A) => booleaneither<A>(p1: (a: A) => boolean, p2: (a: A) => boolean): (a: A) => booleanallPass<A>(preds: ((a: A) => boolean)[]): (a: A) => booleananyPass<A>(preds: ((a: A) => boolean)[]): (a: A) => booleanimport { pipe, A, Logic } from '@stopcock/fp'
const isAdult = (u: User) => u.age >= 18const isActive = (u: User) => u.active
pipe(users, A.filter(Logic.both(isAdult, isActive)))Control flow (dual)
Section titled “Control flow (dual)”equals<A>(a: A, b: A): booleandefaultTo<A>(opt: A | undefined, fallback: A): Awhen_<A>(value: A, pred: (a: A) => boolean, f: (a: A) => A): Aunless<A>(value: A, pred: (a: A) => boolean, f: (a: A) => A): Acond<A, B>(value: A, conditions: [(a: A) => boolean, (a: A) => B][]): B | undefinedimport { pipe, Logic } from '@stopcock/fp'
pipe(undefined, Logic.defaultTo(0)) // 0pipe(5, Logic.defaultTo(0)) // 5
pipe( score, Logic.cond([ [s => s >= 90, () => 'A'], [s => s >= 80, () => 'B'], [s => s >= 70, () => 'C'], [() => true, () => 'F'], ]),)