Skip to main content

Module function

Module function 

Source
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

FunctionSignatureDescription
identityA → AReturns input unchanged
const_A → (() → A)Ignores input, returns constant
alwaysA → (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
absurdNever → AEx 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.