models

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 0 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Optional

type Optional[T any] struct {
	// Value holds the present value when Set is true, including its type's zero value.
	Value T
	// Set distinguishes an absent value from a present zero value.
	Set bool
}

Optional is a simple generic optional type.

See: https://en.wikipedia.org/wiki/Option_type

func EmptyOptional

func EmptyOptional[T any]() Optional[T]

EmptyOptional returns an absent optional containing the type's zero value.

func OptionalPointer added in v0.2.1

func OptionalPointer[T any](value *T) Optional[T]

OptionalPointer copies a non-nil pointed-to value into a present optional; nil produces an absent value.

func OptionalValue added in v0.2.1

func OptionalValue[T any](value T) Optional[T]

OptionalValue marks value as present, even when it is the zero value.

func (Optional[T]) GetOr

func (s Optional[T]) GetOr(defaultValue T) T

GetOr returns the present value or defaultValue without changing the optional.

Directories

Path Synopsis
pgd

Jump to

Keyboard shortcuts

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