opt

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface[Value any] interface {
	// Set the value.
	Set(Value)

	// Get the value, IsNone() MUST be checked before calling this method
	Get() Value

	// Erase the existing value and returns true if there was value.
	//
	// After calling this, IsNone() will return true until Set(T) is called.
	Erase() (hadValue bool)

	// IsNone returns true if there is no value set.
	IsNone() bool

	// IsSome returns true if there is value set.
	IsSome() bool
}

Interface defines required methods for an optional value.

type Value

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

Value.

Zero value means None.

func Maybe

func Maybe[T any](value T, hasValue bool) Value[T]

func Some

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

func (*Value[T]) Erase

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

func (Value[T]) Get

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

func (*Value[T]) IsNone

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

func (*Value[T]) IsSome

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

func (*Value[T]) Set

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

Jump to

Keyboard shortcuts

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