Help us shape the future of Go! Take the 2026 Go Developer Survey

opt

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

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

Option is a type that represents an optional value.

func None

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

None creates a new empty Option[T].

func Some

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

Some creates a new Option[T] with the given value.

func (*Option[T]) Expect

func (o *Option[T]) Expect(msg string) T

Expect panics with the given message if the option is a None value.

func (*Option[T]) IsNone

func (o *Option[T]) IsNone() bool

IsNone returns true if the option is a None value.

func (*Option[T]) IsSome

func (o *Option[T]) IsSome() bool

IsSome returns true if the option is a Some value.

func (Option[T]) IsZero

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

IsZero lets `omitempty` drop this field when it's None (Go 1.20+).

func (Option[T]) MarshalJSON

func (o Option[T]) MarshalJSON() ([]byte, error)

MarshalJSON emits the inner value when Some, or null when None.

func (*Option[T]) UnmarshalJSON

func (o *Option[T]) UnmarshalJSON(b []byte) error

UnmarshalJSON sets None on "null", or decodes T and sets Some.

func (*Option[T]) Unwrap

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

Unwrap panics if the option is a None value.

func (*Option[T]) UnwrapOr

func (o *Option[T]) UnwrapOr(def T) T

UnwrapOr returns the value of the option if it is a Some value, otherwise it returns the given default value.

func (*Option[T]) UnwrapOrElse

func (o *Option[T]) UnwrapOrElse(fn func() T) T

UnwrapOrElse returns the value of the option if it is a Some value, otherwise it returns the result of the given function.

Jump to

Keyboard shortcuts

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