// ets_tracing: off import "../Operator/index.js" import * as C from "../Closure/index.js" /** * Partially Ported from https://github.com/samhh/fp-ts-std * Partially Ported from https://github.com/0x706b/principia */ import * as A from "../Collections/Immutable/Array/index.js" import * as Eq from "../Equal/index.js" import type { Predicate } from "../Function/index.js" import * as I from "../Identity/index.js" import type { Prod, Sum } from "../Newtype/index.js" import { And, BooleanProd, BooleanSum, Or } from "../Newtype/index.js" export const ConjunctionClosure = C.makeClosure((l, r) => And.wrap(And.unwrap(l) && And.unwrap(r)) ) export const DisjunctionClosure = C.makeClosure((l, r) => Or.wrap(Or.unwrap(l) || Or.unwrap(r)) ) export const ProdClosure = C.makeClosure>((l, r) => BooleanProd.wrap(BooleanProd.unwrap(l) && BooleanProd.unwrap(r)) ) export const SumClosure = C.makeClosure>((l, r) => BooleanSum.wrap(BooleanSum.unwrap(l) || BooleanSum.unwrap(r)) ) export const ConjunctionIdentity = I.makeIdentity( And.wrap(true), ConjunctionClosure.combine ) export const DisjunctionIdentity = I.makeIdentity( Or.wrap(false), DisjunctionClosure.combine ) export const ProdIdentity = I.makeIdentity(BooleanProd.wrap(false), ProdClosure.combine) export const SumIdentity = I.makeIdentity(BooleanSum.wrap(false), SumClosure.combine) export const Equal = Eq.strict() export function fold( onFalse: () => A, onTrue: () => B ): (value: boolean) => A | B { return (value) => (value ? onTrue() : onFalse()) } export function not(a: boolean) { return !a } export function invert(b: boolean): boolean { return !b } export function and_(x: boolean, y: boolean): boolean { return x && y } export function and(y: boolean): (x: boolean) => boolean { return (x) => x && y } export function or_(x: boolean, y: boolean): boolean { return x || y } export function or(y: boolean): (x: boolean) => boolean { return (x) => x || y } export function xor_(x: boolean, y: boolean): boolean { return (x && !y) || (!x && y) } export function xor(y: boolean): (x: boolean) => boolean { return (x) => (x && !y) || (!x && y) } export function allPass_(a: A, ps: A.Array>): boolean { return ps.every((f) => f(a)) } export function allPass(ps: A.Array>): (a: A) => boolean { return (a) => ps.every((f) => f(a)) } export function anyPass_(a: A, ps: A.Array>): boolean { return ps.some((f) => f(a)) } export function anyPass(ps: A.Array>): (a: A) => boolean { return (a) => ps.some((f) => f(a)) } export function andPass_(f: Predicate, g: Predicate): Predicate { return (a) => and_(f(a), g(a)) } export function andPass(g: Predicate): (f: Predicate) => Predicate { return (f) => andPass_(f, g) } export function orPass_(f: Predicate, g: Predicate): Predicate { return (a) => or_(f(a), g(a)) } export function orPass(g: Predicate): (f: Predicate) => Predicate { return (f) => orPass_(f, g) }