optionals

package
v0.0.0-...-cd04abb Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 1 Imported by: 7

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
}

An Optional[T] is an option type.

The JSON serialization/deserialization of an Optional[T] is compatible with that of a *T.

func Bind

func Bind[T, U any](opt Optional[T], f func(T) Optional[U]) Optional[U]

func Map

func Map[T, U any](opt Optional[T], f func(T) U) Optional[U]

func None

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

func Some

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

func ToOptional

func ToOptional[T any](ptr *T) Optional[T]

func (Optional[T]) Get

func (opt Optional[T]) Get() (T, bool)

func (Optional[T]) GetOrCompute

func (opt Optional[T]) GetOrCompute(computeValue func() (T, error)) (T, error)

Returns the value inhabiting this option. If this is None, then returns the result of calling the supplied function.

func (Optional[T]) GetOrComputeNoError

func (opt Optional[T]) GetOrComputeNoError(computeValue func() T) T

A version of GetOrCompute that is guaranteed to not error.

func (Optional[T]) GetOrDefault

func (opt Optional[T]) GetOrDefault(defaultValue T) T

Returns the value inhabiting this option. If this is None, then returns the given default value.

func (Optional[T]) IsNone

func (opt Optional[T]) IsNone() bool

func (Optional[T]) IsSome

func (opt Optional[T]) IsSome() bool

func (Optional[T]) MarshalJSON

func (opt Optional[T]) MarshalJSON() ([]byte, error)

func (Optional[T]) ToPtr

func (opt Optional[T]) ToPtr() *T

Converts to a *T. If the Optional is Some, its value is copied.

func (*Optional[T]) UnmarshalJSON

func (opt *Optional[T]) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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