option

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2022 License: MIT Imports: 1 Imported by: 1

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 represents an optional value. The Some variant contains a value and the None variant represents the absence of a value.

func None

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

None instantiates an Option with no value.

func Some

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

Some instantiates an Option with a value.

func (Option[T]) IsNone

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

IsNone returns true if the Option does not contain a value.

func (Option[T]) IsSome

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

IsSome returns true if the Option contains a value.

func (Option[T]) String

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

func (Option[T]) Unwrap

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

Unwrap returns the underlying value of a Some variant, or panics if called on a None variant.

func (Option[T]) UnwrapOr

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

UnwrapOr returns the underlying value of a Some variant, or the provided value on a None variant.

func (Option[T]) UnwrapOrElse

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

UnwrapOrElse returns the underlying value of a Some variant, or the result of calling the provided function on a None variant.

func (Option[T]) UnwrapOrZero

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

UnwrapOrZero returns the underlying value of a Some variant, or the zero value on a None variant.

func (Option[T]) Value

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

Value returns the underlying value and true for a Some variant, or the zero value and false for a None variant.

Jump to

Keyboard shortcuts

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