optional

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 License: MIT Imports: 0 Imported by: 1 module, 1 package

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Value

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

Value is an optional Value containing a value of type T inside.

func Map

func Map[T, U any, F ~func(T) U](v Value[T], f F) Value[U]

Map transforms optional Value[T] to optional Value[U] using the given function.

func New

func New[T any](value T, valid bool) Value[T]

New constructs a new optional Value.

func None

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

None returns an optional Value that has no inner value.

func Some

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

Some returns an optional Value that has provided inner value.

func (Value[T]) IsNone

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

IsNone returns true if the optional Value has no inner value.

func (Value[T]) IsSome

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

IsSome returns true if the optional Value has inner value.

func (Value[T]) Or

func (o Value[T]) Or(other Value[T]) Value[T]

Or returns the Value if it is Some or other Value.

func (Value[T]) OrElse

func (o Value[T]) OrElse(value func() Value[T]) Value[T]

OrElse returns Some(value) if the inner value is present, otherwise it calls provided function and returns its result.

func (Value[T]) OrSome

func (o Value[T]) OrSome(value T) T

OrSome returns the inner value T if present, otherwise it returns provided value.

func (Value[T]) OrZero

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

OrZero returns the inner value T if present, otherwise it returns zero initialized value.

func (*Value[T]) Replace

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

Replace returns a copy of optional Value and resets it to Some(value).

func (*Value[T]) Reset

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

Reset resets the optional Value to None.

func (*Value[T]) Take

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

Take returns a copy of optional Value and resets it to None.

func (Value[T]) Unwrap

func (o Value[T]) Unwrap() (T, bool)

Unwrap returns the inner value of type T and a true if present.

Jump to

Keyboard shortcuts

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