Appearance
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
always
on
applyTo
applyTwice
)identity
Returns its argument unchanged. Useful as a no-op transformer in pipelines.
aivi
identity : A -> Aaivi
use aivi.core.fn (identity)
type Int -> Int
func keepAsIs = n =>
identity nconst
Returns a function that always returns its first argument, ignoring the second. Useful for discarding an input in a pipeline step.
aivi
const : A -> B -> Aaivi
use aivi.core.fn (const)
type Text -> Int
func alwaysForty = ignored =>
const 42 ignoredflip
Reverses the order of the first two arguments of a two-argument function.
aivi
flip : (A -> B -> C) -> B -> A -> Caivi
use aivi.core.fn (flip)
use aivi.math (clamp)
type Int -> Int -> Int -> Int
func clampFlipped = high low n =>
flip clamp high low ncompose
Composes two functions, applying g first and then f. compose f g x is equivalent to f (g x).
aivi
compose : (B -> C) -> (A -> B) -> A -> Caivi
use aivi.core.fn (compose)
use aivi.math (
negate
abs
)
type Int -> Int
func negAbs = n =>
compose negate abs nandThen
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
andThen : (A -> B) -> (B -> C) -> A -> Caivi
use aivi.core.fn (andThen)
use aivi.math (
abs
negate
)
type Int -> Int
func absNeg = n =>
andThen abs negate nalways
Returns a function that ignores its argument and always returns the given value. Equivalent to const with argument order swapped.
aivi
always : A -> B -> Aaivi
use aivi.core.fn (always)
type Text -> Int
func constantZero = ignored =>
always 0 ignoredon
Applies a transformation f to both arguments before combining them with combine. Useful for comparing or combining values after mapping.
aivi
on : (B -> B -> C) -> (A -> B) -> A -> A -> Caivi
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 yapplyTo
Applies a function to a value. applyTo x f is equivalent to f x. Useful for making value-first pipelines.
aivi
applyTo : A -> (A -> B) -> Baivi
use aivi.core.fn (applyTo)
use aivi.math (abs)
type Int -> Int
func applyAbs = n =>
applyTo n absapplyTwice
Applies a function to itself twice: applyTwice f x is equivalent to f (f x).
aivi
applyTwice : (A -> A) -> A -> Aaivi
use aivi.core.fn (applyTwice)
use aivi.math (square)
type Int -> Int
func fourthPower = n =>
applyTwice square n