optionals

package
v0.0.0-...-c6c40b3 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: MIT Imports: 1 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorEmpty = errors.New("optional has no value")
)

Functions

This section is empty.

Types

type Optional

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

func FlatMap

func FlatMap[T any, V any](optional Optional[T], fn func(T) Optional[V]) Optional[V]

func From

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

func FromError

func FromError[T any](value T, err error) Optional[T]

func FromNillable

func FromNillable[T any](value interface{}) Optional[T]

func None

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

func Some

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

func (Optional[T]) FlatMap

func (optional Optional[T]) FlatMap(fn func(T) Optional[any]) Optional[any]

func (Optional[T]) Get

func (optional Optional[T]) Get() T

func (Optional[T]) GetDefault

func (optional Optional[T]) GetDefault(value T) T

func (Optional[T]) GetElse

func (optional Optional[T]) GetElse(fn func() T) T

func (Optional[T]) GetPtr

func (optional Optional[T]) GetPtr() *T

func (Optional[T]) GetTry

func (optional Optional[T]) GetTry() (value T, err error)

func (Optional[T]) IfPresent

func (optional Optional[T]) IfPresent(fn func(T))

func (Optional[T]) IfPresentElse

func (optional Optional[T]) IfPresentElse(fn func(T), fn_ func())

func (Optional[T]) IsEmpty

func (optional Optional[T]) IsEmpty() bool

func (Optional[T]) IsPresent

func (optional Optional[T]) IsPresent() bool

func (Optional[T]) Map

func (optional Optional[T]) Map(fn func(T) T)

Jump to

Keyboard shortcuts

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