data.function ≡
inline auto id(auto x) §
Identity function.
prop> id(x) == x
inline auto constant(auto x) §
Return a generic closure which ignores its argument and always
returns x
Example
>>> apply(constant(false), 10)
false
inline auto compose((auto) -> auto f, (auto) -> auto g) §
Function composition
inline auto compose2((auto) -> auto f, (auto, auto) -> auto g) §
Composition with a binary function
Example
>>> zip_with(compose2(reinterpret_cast<uint32>, f32::mul), {1.2, 3.0}, {9.0, 4.3})
{0xCD, 0x67}
inline auto apply((auto) -> auto f, auto x) §
Apply one argument to a curried function
inline auto curry((auto, auto) -> auto f) §
Curry a binary function
A curried function is a function that takes one argument at a time.
For example, a curried binary functions is a unary function that
returns a unary function. Curried functions can be applied using
apply or converted into uncurried functions using
uncurry.
prop> apply(apply(curry(add), 1), 2) == add(1, 2)
inline auto curry3((auto, auto, auto) -> auto f) §
inline auto uncurry1((auto) -> auto f) §
Convert a curried function into uncurried unary function
inline auto uncurry((auto) -> auto f) §
Convert a curried function into uncurried binary function
inline auto uncurry3((auto) -> auto f) §
Convert a curried function into uncurried three parameter function
inline auto bind((auto) -> auto f, auto x) §
Bind a value to the function argument
inline auto bind1st((auto, auto) -> auto f, auto x) §
Bind a value to the first argument of a function
Example
>>> apply(bind1st(sub, 6), 3)
3
inline auto on1st((auto) -> auto f) §
Apply a function to the first argument
inline auto bind2nd((auto, auto) -> auto f, auto y) §
Bind a value to the second argument of a function
Example
>>> apply(bind2nd(sub, 2), 6)
4
inline auto on2nd((auto) -> auto f) §
Apply a function to the second argument
inline auto not((auto) -> bool f) §
Return true if the unary predicate is false
Example
>>> apply(not(is_valid), make_optional(true, 10))
false
inline auto not2((auto, auto) -> bool f) §
Return true if the binary predicate is false
Example
>>> zip_with(not2(less_than), {1, 2}, {3, 1});
{false, true}
inline auto selecting((auto, auto) -> bool f) §
Select one of two arguments using the binary predicate
Example
>>> reduce(selecting(less_then), {1, 4, 0});
0
inline auto flip((auto, auto) -> auto f) §
Flip function parameters
Example
>>> zip_with(flip(less_than), {1, 2}, {3, 1});
{false, true}
template <auto N> inline auto compose_endo((auto) -> auto f) §
Compose the function N times.
Examples
>>> apply(compose_endo<3>(increment), 1)
4
>>> apply(compose_endo<3>(compose_endo<2>(increment)), 1)
7