funcs

package
v0.0.0-...-4dd3f74 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 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 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