/** * EVA Algebra — Composition operators. * * ⊗ Sequential: seq(f, g)(x) = g(f(x)) * ∥ Parallel: par(f, g)(a, b) = [f(a), g(b)] * ⊕ Conditional: cond(p,f,g)(x) = p(x) ? f(x) : g(x) */ export const seq = (f: (a: A) => B, g: (b: B) => C): (a: A) => C => (a) => g(f(a)); export const par = ( f: (a: A1) => B1, g: (a: A2) => B2 ): (a: A1, b: A2) => [B1, B2] => (a, b) => [f(a), g(b)]; export const cond = ( pred: (x: T) => boolean, f: (x: T) => R, g: (x: T) => R ): (x: T) => R => (x) => pred(x) ? f(x) : g(x); export const pipeline = (init: T, steps: Array<(x: T) => T>): T => steps.reduce((acc, f) => f(acc), init); export const compose = (...fns: Array<(x: T) => T>): (x: T) => T => (x) => pipeline(x, fns);