Skip to content

aivi.core.fn ​

Higher-order function combinators. This module provides building blocks for working with functions as first-class values — composing, flipping, and applying them in pipelines.

aivi
use aivi.core.fn (
    identity
    const
    flip
    compose
    andThen
    on
)

At a glance ​

FunctionTypeUse it for
identityA -> AReturn a value unchanged
constA -> B -> AIgnore the second argument and keep the first
flip(A -> B -> C) -> B -> A -> CReverse the first two arguments of a function
compose(B -> C) -> (A -> B) -> A -> CRight-to-left composition
andThen(A -> B) -> (B -> C) -> A -> CLeft-to-right composition
on(B -> B -> C) -> (A -> B) -> A -> A -> CCompare or combine after projecting both sides

identity ​

Returns its argument unchanged. Useful as a no-op transformer in pipelines.

aivi
use aivi.core.fn (identity)

type Int -> Int
func keepAsIs =
  |> identity

const ​

Returns a function that always returns its first argument, ignoring the second. Useful for discarding an input in a pipeline step.

aivi
use aivi.core.fn (const)

type Text -> Int
func alwaysFortyTwo =
  |> const 42

flip ​

Reverses the order of the first two arguments of a two-argument function.

aivi
use aivi.core.fn (flip)

use aivi.math (clamp)

type Int -> Int -> Int -> Int
func clampFlipped = high low n =>
    flip clamp high low n

compose ​

Composes two functions, applying g first and then f. compose f g x is equivalent to f (g x).

aivi
use aivi.core.fn (compose)

use aivi.math (
    negate
    abs
)

type Int -> Int
func negAbs =
  |> compose negate abs

andThen ​

Applies f first and then g. The reverse of compose. andThen f g x is equivalent to g (f x). Often called "left-to-right composition" or >>>.

aivi
use aivi.core.fn (andThen)

use aivi.math (
    abs
    negate
)

type Int -> Int
func absNeg =
  |> andThen abs negate

on ​

Applies a transformation f to both arguments before combining them with combine. Useful for comparing or combining values after mapping.

aivi
use aivi.core.fn (on)

use aivi.math (abs)

type Int -> Int -> Bool
func byInt = left right =>
    left < right

type Int -> Int -> Bool
func absCompare = x y =>
    on byInt abs x y

(c) 2026 by Andreas Herd