lazy

package
v2.22.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package lazy provides a lazy value implementation. It's useful especially in global variable initialization to avoid slowing down the program startup time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Value

type Value[T any] struct {
	// contains filtered or unexported fields
}

func New

func New[T any](fn func() T) *Value[T]

New creates a new lazy value with the given load function.

func (*Value[T]) Load

func (v *Value[T]) Load() T

type ValueWithError added in v2.22.0

type ValueWithError[T any] struct {
	// contains filtered or unexported fields
}

func NewWithError added in v2.22.0

func NewWithError[T any](fn func() (T, error)) *ValueWithError[T]

NewWithError allows you to provide a lazy initializer that can fail.

func (*ValueWithError[T]) Load added in v2.22.0

func (v *ValueWithError[T]) Load() (T, error)

Jump to

Keyboard shortcuts

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