Documentation
¶
Overview ¶
Package optional provides a type which can be used to represent a value that may or may not be present like option in Rust.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type O ¶
type O[T any] struct { // contains filtered or unexported fields }
func FromValue2 ¶
FromValue2 creates an Optional from a value and a boolean meaning whether the value is valid.
HINT:
if we have a function defined as fn () (T, bool), we can use FromValue2(fn()) instead of if v, ok := fn(); ok { FromValue(v) } else { Empty[T]() }
func (O[T]) Must ¶
func (o O[T]) Must() T
Must directly return the value of the Optional.
❌WARNING: Panic if the Optional has no value.
func (O[T]) Ptr ¶
func (o O[T]) Ptr() *T
Ptr returns a pointer to the value of the Optional. return nil if the Optional has no value.
func (O[T]) ValueOr ¶
func (o O[T]) ValueOr(dft T) T
ValueOr returns the value of the Optional if it has a valid value, otherwise returns the given default value.
func (O[T]) ValueOrZero ¶
func (o O[T]) ValueOrZero() T
ValueOrZero returns the value of the Optional if it has a valid value, otherwise returns the zero value of T.