optional

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: Apache-2.0 Imports: 0 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface added in v0.11.0

type Interface[T any] interface {
	// Set the optional value
	Set(T)

	// Get the optional value, IsNil() MUST be checked before calling this method
	Get() T

	// Erase the optional value, after calling this, IsNil() will return true
	// until Set(T) is called.
	Erase() bool

	// IsNil returns true when there is no optional value
	IsNil() bool
}

Interface defines the interface of an optional value

type Value

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

func NonNilValue added in v0.12.0

func NonNilValue[T any](v T) Value[T]

func (*Value[T]) Erase

func (o *Value[T]) Erase() (hadValue bool)

Erase implements Interface, it will never panic

func (*Value[T]) Get

func (o *Value[T]) Get() T

Get implements Interface, it panics when Value[T] is nil

func (*Value[T]) IsNil

func (o *Value[T]) IsNil() bool

IsNil implements Interface, it will never panic

func (*Value[T]) Set

func (o *Value[T]) Set(v T)

Set implements Interface, it panics when Value[T] is nil

Jump to

Keyboard shortcuts

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