option

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2022 License: BSD-2-Clause 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 manages an option contained value, i.e. a value that may or may not be present.

func Empty

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

Empty returns an empty Option

func Of

func Of[T any](value T, present bool) Option[T]

Of create an Option

func OfValue

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

OfValue create a non-empty Option, with a value

func (Option[T]) Must

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

Must return the value Option contains. If value is not present, panics

func (Option[T]) OrCompute

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

OrCompute return the value Option contains. If value is not present, return a value computed by the func.

func (Option[T]) OrElse

func (o Option[T]) OrElse(defaultValue T) T

OrElse return the value Option contains. If value is not present, return a default value.

func (Option[T]) OrNext

func (o Option[T]) OrNext(next func() Option[T]) Option[T]

OrNext return the Option if it is present. If value is not present, return an Option computed by the func.

func (Option[T]) Present

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

Present returns if option value is present

func (Option[T]) Unpack

func (o Option[T]) Unpack() (value T, present bool)

Unpack returns the state of option

Jump to

Keyboard shortcuts

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