optional

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Try added in v0.0.9

func Try(action func()) error

Types

type Value

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

Value[T] is an optional value of type T, meaning it can represent the lack of value.

func Access added in v0.0.9

func Access[OBJ, F any](opt Value[OBJ], field string) Value[F]

func Copy added in v0.0.8

func Copy[T any](opt Value[T]) Value[T]

Copy allows to make a deep copy of optional.Value. optional.Values share references by default.

func Missing added in v0.0.6

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

Missing is equivalent to Nil but renamed for some usecase.

func Nil added in v0.0.6

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

Nil is a function to make an optional.Value without a value; it is equivalent to optional.Value's zero value

func Some

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

Some is a function to make an optional.Value with a value

func TryErr added in v0.0.9

func TryErr[T any](action func() T) (ret Value[T], err error)

func TryExpr added in v0.0.9

func TryExpr[T any](action func() T) (ret Value[T])

func (Value[T]) Eq

func (opt Value[T]) Eq(val T) bool

Eq is the "==" operator for optional.Value. It works on the sub type only.

func (Value[T]) EqOpt

func (opt Value[T]) EqOpt(val Value[T]) bool

EqQpt is the "==" operator for optional.Value between optional.Values

func (Value[T]) HasValue

func (opt Value[T]) HasValue() bool

HasValue return true if the optional.Value has a value

func (Value[T]) LookupValue

func (opt Value[T]) LookupValue() (T, bool)

LookupValue return the containing value value or the a zero value if the optional.Value doesn't have a value, and a boolean to true if it contains a value

func (Value[T]) MarshalBSONValue

func (opt Value[T]) MarshalBSONValue() (bsontype.Type, []byte, error)

func (Value[T]) MarshalJSON

func (opt Value[T]) MarshalJSON() ([]byte, error)

func (*Value[T]) Set

func (opt *Value[T]) Set(val T)

Set allows to set a value to the optional.Value

func (*Value[T]) SetNil

func (opt *Value[T]) SetNil()

SetNil allows to set "nil" to the optional.Value, meaning it remove the value from it

func (Value[T]) String added in v0.0.7

func (opt Value[T]) String() string

String is the string representation of optional.Value

func (*Value[T]) UnmarshalBSONValue

func (opt *Value[T]) UnmarshalBSONValue(t bsontype.Type, data []byte) (err error)

func (*Value[T]) UnmarshalJSON

func (opt *Value[T]) UnmarshalJSON(data []byte) error

func (Value[T]) Value

func (opt Value[T]) Value() T

Value force to get the value of the optional value. If it hadn't a value it will panic

func (Value[T]) ValueOr

func (opt Value[T]) ValueOr(val T) T

ValueOr allow to get the containing value or a default value if the optional.Value didn't have any value

Jump to

Keyboard shortcuts

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