optional

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Optional

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

Optional is a type that may or may not contain a non-nil value.

func Default

func Default[T any]() Optional[T]

Default returns an default Optional instance.

func FromNillable

func FromNillable[T any](value *T) Optional[T]

FromNillable returns an Optional for a given value, which may be nil.

func Of

func Of[T any](value T) Optional[T]

Of returns an Optional with a non-nil value.

func (Optional[T]) IfNotNil

func (o Optional[T]) IfNotNil(action func(value T))

IfNotNil performs the given action with the value if a value is not nil.

func (Optional[T]) IfNotNilOrElse

func (o Optional[T]) IfNotNilOrElse(action func(value T), fallbackAction func())

IfNotNilOrElse performs the action with the value if present, otherwise performs the fallback action.

func (Optional[T]) IsNil

func (o Optional[T]) IsNil() bool

IsNil checks if the Optional is nil.

func (Optional[T]) IsNotNil

func (o Optional[T]) IsNotNil() bool

IsNotNil checks if there is a value present.

func (Optional[T]) OrElse

func (o Optional[T]) OrElse(other T) T

OrElse returns the value if is not nil, otherwise returns other.

func (Optional[T]) OrElseGet

func (o Optional[T]) OrElseGet(action func() T) T

OrElseGet returns the value if is not nil, otherwise invokes action and returns the result.

func (Optional[T]) OrElseTrigger

func (o Optional[T]) OrElseTrigger(errorHandler func() error) (T, error)

OrElseTrigger returns the value if present, otherwise returns an error.

func (Optional[T]) Unwarp

func (o Optional[T]) Unwarp() T

Unwarp returns the value if not nil, otherwise panics.

Jump to

Keyboard shortcuts

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