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

option

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 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 Option

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

func Cast

func Cast[T any, U any](option Option[T]) Option[U]

func From

func From[T *any](t T) Option[T]

func Map

func Map[T any, U any](option Option[T], fn func(T) U) Option[U]

This function applies the given function to the Option value and returns the result.

func None

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

func Ref

func Ref[T any](o *Option[T]) Option[*T]

func Some

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

func (Option[T]) AndThen

func (o Option[T]) AndThen(fn func(T) bool) bool

func (Option[T]) IsNone

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

Returns true if the Option does not contain a value, false otherwise.

Inverse of IsSome

func (Option[T]) IsSome

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

Returns true if the Option contains a value, false otherwise.

Inverse of IsNone

func (Option[T]) Split

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

func (Option[T]) Then

func (o Option[T]) Then(fn func(T))

func (Option[T]) ThenPtr

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

func (Option[T]) Unwrap

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

This function returns a copy of the data and not a pointer to it. Panics if the Option is None.

Modifying the result will not modify the original data instead use UnwrapPtr or Map

func (Option[T]) UnwrapOr

func (o Option[T]) UnwrapOr(t T) T

func (Option[T]) UnwrapOrElse

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

func (Option[T]) UnwrapPtr

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

This function returns a pointer to the data contained in the Option. Panics if the Option is None.

Jump to

Keyboard shortcuts

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