Data and Math
vfunc
Compose, adapt and reuse functions that take one or two arguments.
Released v1.0.0 · 2026-09-28use "stdlib/func.ven"
Compose, transform, and pass functions around with no friction.
print identity(42)
:: 42
API reference
constant(x)
Builds a zero-argument function that always gives back x.
print constant(7)()
:: prints: 7compose2(f, g)
Composes two one-argument functions into one: f after g.
make double(x)
give x * 2
make add_one(x)
give x + 1
print compose2(add_one, double)(3)
:: prints: 7pipe(value, functions)
Threads value through every one-argument function in functions, left to right.
make double(x)
give x * 2
make add_one(x)
give x + 1
print pipe(3, [double, add_one])
:: prints: 7flip(fn)
Swaps the argument order of a two-argument function.
make subtract(a, b)
give a - b
print flip(subtract)(2, 10)
:: prints: 8once(fn)
Wraps fn so it only ever actually runs on its first call.
state = new_map()
map_set(state, "n", 0)
make bump()
n = map_get(state, "n") + 1
map_set(state, "n", n)
give n
once_fn = once(bump)
print once_fn()
print once_fn()
:: prints: 1
:: prints: 1memoize(fn)
Wraps a one-argument function fn so repeat calls with the same argument are cached.
make square(x)
give x * x
sq = memoize(square)
print sq(4)
print sq(4)
:: prints: 16
:: prints: 16curry2(fn)
Curries a two-argument function into two chained one-argument calls.
make add(a, b)
give a + b
add3 = curry2(add)(3)
print add3(4)
:: prints: 7partial1(fn, bound_first)
Binds the first argument of a two-argument function, leaving the second open.
make add(a, b)
give a + b
add10 = partial1(add, 10)
print add10(5)
:: prints: 15