Documentation
¶
Index ¶
- type Optional
- func (opt Optional[T]) Get() (T, bool)
- func (opt Optional[T]) GetOrCompute(computeValue func() (T, error)) (T, error)
- func (opt Optional[T]) GetOrComputeNoError(computeValue func() T) T
- func (opt Optional[T]) GetOrDefault(defaultValue T) T
- func (opt Optional[T]) IsNone() bool
- func (opt Optional[T]) IsSome() bool
- func (opt Optional[T]) MarshalJSON() ([]byte, error)
- func (opt Optional[T]) MarshalYAML() (interface{}, error)
- func (opt Optional[T]) ToPtr() *T
- func (opt *Optional[T]) UnmarshalJSON(data []byte) error
- func (opt *Optional[T]) UnmarshalYAML(unmarshal func(interface{}) error) error
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 }
An Optional[T] is an option type.
The JSON and YAML serialization/deserialization of an Optional[T] are compatible with that of a *T.
func ToOptional ¶
func (Optional[T]) GetOrCompute ¶
Returns the value inhabiting this option. If this is None, then returns the result of calling the supplied function.
func (Optional[T]) GetOrComputeNoError ¶
func (opt Optional[T]) GetOrComputeNoError(computeValue func() T) T
A version of GetOrCompute that is guaranteed to not error.
func (Optional[T]) GetOrDefault ¶
func (opt Optional[T]) GetOrDefault(defaultValue T) T
Returns the value inhabiting this option. If this is None, then returns the given default value.
func (Optional[T]) MarshalJSON ¶
func (Optional[T]) MarshalYAML ¶
func (Optional[T]) ToPtr ¶
func (opt Optional[T]) ToPtr() *T
Converts to a *T. If the Optional is Some, its value is copied.
func (*Optional[T]) UnmarshalJSON ¶
func (*Optional[T]) UnmarshalYAML ¶
Click to show internal directories.
Click to hide internal directories.