optional

package
v0.8.8 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MPL-2.0 Imports: 0 Imported by: 11 modules, 15 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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