optional

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: MPL-2.0 Imports: 0 Imported by: 12

Documentation

Overview

Package optional contains optional type.

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 represents a type T that may be "null" - that, which value is missing.

func None

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

None is helper function which returns empty Optional.

func Some

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

Some creates a new Optional with provided value.

func (Optional[T]) Get

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

Get returns a value, true on non-empty optional and zero-value and false otherwise.

func (Optional[T]) IsPresent

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

IsPresent tells of there any value inside the optional.

func (Optional[T]) Ptr

func (o Optional[T]) Ptr() *T

Ptr returns a pointer to value or nil pointer. It is safe to change the value inside the pointer (if the T type supports this).

func (Optional[T]) ValueOr

func (o Optional[T]) ValueOr(val T) T

ValueOr returns a value on non-empty optional or provided value otherwise.

func (Optional[T]) ValueOrZero

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

ValueOrZero returns a value on non-empty optional and zero-value otherwise.

Jump to

Keyboard shortcuts

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