clm_rust_core/layer0/functional.rs
1//! Pure function combinators for the Set category (INV-599): identity, compose, pipe.
2//!
3//! `compose(g, f)(x) == g(f(x))` (right to left) and `pipe(f, g)(x) == g(f(x))` (left to right).
4//! Both are associative with `identity` as unit.
5
6/// `id_A(x) = x`.
7pub fn identity<T>(value: T) -> T {
8 value
9}
10
11/// Right-to-left composition: `compose(g, f)(x) == g(f(x))`.
12pub fn compose<A, B, C>(g: impl Fn(B) -> C, f: impl Fn(A) -> B) -> impl Fn(A) -> C {
13 move |value| g(f(value))
14}
15
16/// Left-to-right composition: `pipe(f, g)(x) == g(f(x))`.
17pub fn pipe<A, B, C>(f: impl Fn(A) -> B, g: impl Fn(B) -> C) -> impl Fn(A) -> C {
18 move |value| g(f(value))
19}