optional

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2025 License: MIT Imports: 1 Imported by: 0

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 {
	// contains filtered or unexported fields
}

Optional is a type that represents an optional value

func CastInt

func CastInt[A, B constraints.Integer](a Optional[A]) (out Optional[B])

CastInt converts an integer optional value to another type

func None

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

None creates an optional value with no value set

func Some

func Some[T any](v T) Optional[T]

Some creates an optional value with the given value

func (Optional[T]) Get

func (o Optional[T]) Get() (T, bool)

Get returns the optional value and a boolean indicating if the value is set

func (Optional[T]) GetOr

func (o Optional[T]) GetOr(def T) T

GetOr returns the optional value or a default value if the value is not set

func (Optional[T]) IsSet

func (o Optional[T]) IsSet() bool

IsSet returns true if the optional value is set

func (*Optional[T]) Set

func (o *Optional[T]) Set(v T)

Set sets the optional value

func (*Optional[T]) Unset

func (o *Optional[T]) Unset()

Unset unsets the optional value

func (Optional[T]) Unwrap

func (o Optional[T]) Unwrap() T

Unwrap returns the optional value or panics if the value is not set

Jump to

Keyboard shortcuts

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