Documentation ¶
Overview ¶
Package funcs provides utilities for functions, such as caching and memoization.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Memoize ¶
Memoize the result of a function call.
fn is only ever called once, even if it returns an error.
func MemoizeArg ¶
func MemoizeArg[K comparable, T any](fn func(K) (T, error)) func(K) (T, error)
MemoizeArg memoizes the result of a function call based on the argument.
fn is only ever called once for each argument, even if it returns an error.
func MemoizeArgNoError ¶
func MemoizeArgNoError[K comparable, T any](fn func(K) T) func(K) T
MemoizeArgNoError memoizes the result of a function call based on the argument.
fn is only ever called once for each argument
func MemoizeNoError ¶
func MemoizeNoError[T any](fn func() T) func() T
MemoizeNoError the result of a function call.
fn is only ever called once
Types ¶
type CachedFunc ¶
CachedFunc represents a function which caches its result, but can also be flushed.
func Cache ¶
func Cache[T any](fn func() (*T, error)) CachedFunc[T]
Cache the result of a function call, with the ability to flush the cache.
func CacheWithCallback ¶
func CacheWithCallback[T any](fn func() (*T, error), cb func()) CachedFunc[T]
CacheWithCallback the result of a function call, with the ability to flush the cache. The provided callback function will be called when the cache is flushed.