Expand description
Functions — morphisms in the category of types.
Functions are the arrows (morphisms) that connect types. This module provides the fundamental function combinators that form the basis of functional programming.
§Core Combinators
| Function | Signature | Description |
|---|---|---|
identity | A → A | Returns input unchanged |
const_ | A → (() → A) | Ignores input, returns constant |
always | A → (B → A) | Ignores any input, returns constant |
compose | (B → C) → (A → B) → (A → C) | Right-to-left composition |
flip | ((A, B) → C) → ((B, A) → C) | Swap arguments |
absurd | Never → A | Ex falso quodlibet |
§Laws
- Left identity:
compose(identity, f) ≡ f - Right identity:
compose(f, identity) ≡ f - Associativity:
compose(f, compose(g, h)) ≡ compose(compose(f, g), h) - Flip involution:
flip(flip(f)) ≡ f
Functions§
- absurd
- Eliminate the never type by producing any value.
- always
- Create a constant function that ignores any argument and returns
value. - and_
then - Left-to-right function composition (flip of compose).
- compose
- Right-to-left function composition.
- const_
- Create a constant function that ignores unit and returns
value. - flip
- Swap the arguments of a two-argument function.
- identity
- The identity function — returns its argument unchanged.
- pipe1
- Apply a single function to a value (unary pipe).
- pipe2
- Apply two functions in sequence (binary pipe).
- pipe3
- Apply three functions in sequence (ternary pipe).
- tupled
- Convert a two-argument function to accept a tuple.
- untupled
- Convert a tuple-accepting function to take two arguments.