x-lang

← Index

x/core/fn

Higher-order function combinators, homed on the Fn class.

Function combinators as static methods: (Fn compose f g), (Fn flip f), (Fn tap f).

Class Fn

(Fn identity x)

Return the given value unchanged.

Parameters:

Returns: ANY — The input value unchanged

(Fn const x)

Return a function that always returns x, ignoring its argument.

Parameters:

Returns: CALLABLE — A function that always returns x

(Fn compose f g)

Right-to-left composition: (Fn compose f g) applies g then f.

Parameters:

Returns: CALLABLE — Composed function f(g(x))

Examples:

((Fn compose (method-ref Num inc) (method-ref Num inc)) 1) => 3

(Fn pipe f g)

Left-to-right composition: (Fn pipe f g) applies f then g.

Parameters:

Returns: CALLABLE — Piped function g(f(x))

(Fn curry f x)

Partially apply a binary function by fixing its first argument.

Parameters:

Returns: CALLABLE — Function awaiting one argument

(Fn flip f)

Return a function that calls f with its two arguments reversed.

Parameters:

Returns: CALLABLE — Function with reversed argument order

(Fn tap f)

Call f on the argument for side effects, then return the argument.

Parameters:

Returns: CALLABLE — Function applying f then returning its argument

(Fn default-to d x)

Return x if non-nil, otherwise return the default d.

Parameters:

Returns: ANY — x if non-nil, otherwise d

(Fn until pred f x)

Repeatedly apply f to x until pred is satisfied, then return the value.

Parameters:

Returns: ANY — First value satisfying pred

(Fn complement pred)

Return a function that negates a predicate.

Parameters:

Returns: CALLABLE — Negated predicate

(Fn partial f . bound)

Partially apply a function with leading arguments.

Parameters:

Returns: CALLABLE — Partially applied function

(Fn juxt . fns)

Create a function that applies multiple functions and collects results.

Parameters:

Returns: CALLABLE — Juxtaposed function

(Fn both f g)

Combine two predicates with AND.

Parameters:

Returns: CALLABLE — Combined predicate

(Fn either f g)

Combine two predicates with OR.

Parameters:

Returns: CALLABLE — Combined predicate

(Fn all-pass preds)

Return a predicate that passes when all predicates pass.

Parameters:

Returns: CALLABLE — Combined predicate

(Fn any-pass preds)

Return a predicate that passes when any predicate passes.

Parameters:

Returns: CALLABLE — Combined predicate