gemo
Functions
pub fn memoize0(func: fn() -> a, cb: fn() -> a) -> a
Takes the parent function as a key and executes the callback if its output is not already cached. This should be called with a use expression at the top of the function
Example:
fn complex_task() {
use <- glemo.memoize0(complex_task)
"./huge_file.csv"
|> read_file
|> hash
}
pub fn memoize1(func: fn(a) -> b, arg1: a, cb: fn() -> b) -> b
Takes the parent function and its args as a key and executes the callback if its output is not already cached. This should be called with a use expression at the top of the function
Example:
fn fib(n) {
use <- glemo.memoize1(fib, n)
use <- bool.guard(n <= 1, n)
fib(n - 1) + fib(n - 2)
}
pub fn memoize10(
func: fn(a, b, c, d, e, f, g, h, i, j) -> k,
arg1: a,
arg2: b,
arg3: c,
arg4: d,
arg5: e,
arg6: f,
arg7: g,
arg8: h,
arg9: i,
arg10: j,
cb: fn() -> k,
) -> k
Same as memoize1 but with 10 args.
pub fn memoize2(
func: fn(a, b) -> c,
arg1: a,
arg2: b,
cb: fn() -> c,
) -> c
Same as memoize1 but with 2 args.
pub fn memoize3(
func: fn(a, b, c) -> d,
arg1: a,
arg2: b,
arg3: c,
cb: fn() -> d,
) -> d
Same as memoize1 but with 3 args.
pub fn memoize4(
func: fn(a, b, c, d) -> e,
arg1: a,
arg2: b,
arg3: c,
arg4: d,
cb: fn() -> e,
) -> e
Same as memoize1 but with 4 args.
pub fn memoize5(
func: fn(a, b, c, d, e) -> f,
arg1: a,
arg2: b,
arg3: c,
arg4: d,
arg5: e,
cb: fn() -> f,
) -> f
Same as memoize1 but with 5 args.
pub fn memoize6(
func: fn(a, b, c, d, e, f) -> g,
arg1: a,
arg2: b,
arg3: c,
arg4: d,
arg5: e,
arg6: f,
cb: fn() -> g,
) -> g
Same as memoize1 but with 6 args.
pub fn memoize7(
func: fn(a, b, c, d, e, f, g) -> h,
arg1: a,
arg2: b,
arg3: c,
arg4: d,
arg5: e,
arg6: f,
arg7: g,
cb: fn() -> h,
) -> h
Same as memoize1 but with 7 args.
pub fn memoize8(
func: fn(a, b, c, d, e, f, g, h) -> i,
arg1: a,
arg2: b,
arg3: c,
arg4: d,
arg5: e,
arg6: f,
arg7: g,
arg8: h,
cb: fn() -> i,
) -> i
Same as memoize1 but with 8 args.
pub fn memoize9(
func: fn(a, b, c, d, e, f, g, h, i) -> j,
arg1: a,
arg2: b,
arg3: c,
arg4: d,
arg5: e,
arg6: f,
arg7: g,
arg8: h,
arg9: i,
cb: fn() -> j,
) -> j
Same as memoize1 but with 9 args.
pub fn reset_cache() -> Nil