optional

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2025 License: AGPL-3.0-or-later Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type V

type V[T any] struct {
	Value   T
	Present bool
}

V is a value that may or may not be present.

func Deref

func Deref[T any](ptr *T) V[T]

Deref creates a new optional value from a pointer.

If the pointer is non-nil, it is dereferenced and set as the value.

func Empty

func Empty[T any]() V[T]

Empty creates a new optional value that is not present.

func New

func New[T any](value T) V[T]

New creates a new optional value with the given value.

func (V[T]) IsPresent

func (v V[T]) IsPresent() bool

IsPresent checks if the optional value is present.

func (V[T]) IsZero

func (v V[T]) IsZero() bool

IsZero checks if the optional value is not present.

func (V[T]) Ref

func (v V[T]) Ref() *T

Ref returns a pointer to the value if it is present, or nil if it is not.

Jump to

Keyboard shortcuts

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