funcs

package
v0.0.0-...-bb3031d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

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

func Memoize[T any](fn func() (T, error)) func() (T, error)

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

type CachedFunc[T any] interface {
	Do() (*T, error)
	Flush()
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL