option

package
v0.0.0-...-1db7b98 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyOption = errors.New("expected Option value was empty")

ErrEmptyOption is returned by Option.Unwrap when attempting to retrieve a value from an empty Option.

Functions

This section is empty.

Types

type Conversion

type Conversion[T any, U any] func(T) (U, error)

Conversion is a function that converts a T into a U.

type Option

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

Option represents an optional type.

func Map

func Map[T any, U any](opt Option[T], convert Conversion[T, U]) (Option[U], error)

Map transforms an Option[T] into an Option[U] by applying the given conversion to T. None[T] is returned as None[U].

Errors

  • Any error returned by the conversion.

func None

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

None returns an empty Option[T] whose zero-value is considered valid by [Option.NonZero] and [NonZero].

func Some

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

Some returns an Option[T] populated with the given type.

func (Option[T]) GoString

func (o Option[T]) GoString() string

func (Option[T]) IsSome

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

IsSome returns true if the Option is populated with a non-zero value.

func (Option[T]) String

func (o Option[T]) String() string

func (*Option[T]) UnmarshalJSON

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

func (Option[T]) Unwrap

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

Unwrap returns the value of the Option, or ErrEmptyOption error if the Option is empty.

func (Option[T]) UnwrapOrZero

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

UnwrapOrZero returns the value of the Option, which is the zero-value of T if the Option is None.

Jump to

Keyboard shortcuts

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