Documentation
¶
Overview ¶
Example ¶
val := None[int]() val = Of(2) slc, err := val.MarshalJSON() fmt.Println(string(slc), err) ptr := val.Ptr() fmt.Println(*ptr)
Output: 2 <nil> 2
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Optional ¶
type Optional[T any] struct { // contains filtered or unexported fields }
Optional represents a type T that may be "null" - that, which value is missing.
func (Optional[T]) Get ¶
Get returns a value, true on non-empty optional and zero-value and false otherwise.
func (Optional[T]) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Optional[T]) Ptr ¶
func (o Optional[T]) Ptr() *T
Ptr returns a pointer to value or nil pointer. It is safe to change the value inside the pointer (if the T type supports this).
func (*Optional[T]) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler
func (Optional[T]) ValueOr ¶
func (o Optional[T]) ValueOr(val T) T
ValueOr returns a value on non-empty optional or provided value otherwise.
func (Optional[T]) ValueOrZero ¶
func (o Optional[T]) ValueOrZero() T
ValueOrZero returns a value on non-empty optional and zero-value otherwise.
Click to show internal directories.
Click to hide internal directories.