optional

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool int8
const (
	// BoolNone returns a Bool no value set.
	BoolNone Bool = -1
	// False returns a Bool false value set.
	False Bool = 0
	// True returns a Bool true value set.
	True Bool = 1
)

func BoolSome

func BoolSome(v bool) Bool

BoolSome returns an Bool with the given value set.

func (Bool) Get

func (b Bool) Get() (value bool, isSet bool)

Get returns the stored value and a boolean indicating whether it is set.

func (Bool) IsSet

func (b Bool) IsSet() bool

IsSet reports whether the Option contains a value.

func (Bool) MustGet

func (b Bool) MustGet() bool

MustGet returns the stored value or panics if no value is set.

func (Bool) Or

func (b Bool) Or(def bool) bool

Or returns the stored value if set, otherwise returns the provided default.

func (*Bool) Set

func (b *Bool) Set(v bool)

Set assigns a value and marks the Option as set.

func (*Bool) Unset

func (b *Bool) Unset()

Unset clears the value and marks the Option as not set.

type Option

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

Option represents a value that may or may not be present.

func From

func From[T any](v T, ok bool) Option[T]

From constructs an Option from a value and a presence flag.

func None

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

None returns an empty Option with no value set.

func Some

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

Some returns an Option with the given value set.

func (Option[T]) Get

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

Get returns the stored value and a boolean indicating whether it is set.

func (Option[T]) IsSet

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

IsSet reports whether the Option contains a value.

func (Option[T]) MustGet

func (o Option[T]) MustGet() T

MustGet returns the stored value or panics if no value is set.

func (Option[T]) Or

func (o Option[T]) Or(def T) T

Or returns the stored value if set, otherwise returns the provided default.

func (*Option[T]) Set

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

Set assigns a value and marks the Option as set.

func (*Option[T]) Unset

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

Unset clears the value and marks the Option as not set.

Jump to

Keyboard shortcuts

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