Documentation
¶
Index ¶
- type Option
- func (t Option[T]) Defined() bool
- func (t Option[T]) Empty() bool
- func (t Option[T]) Get() T
- func (t Option[T]) MarshalJSON() ([]byte, error)
- func (t Option[T]) MarshalYAML() (interface{}, error)
- func (t Option[T]) OrElse(v T) T
- func (t Option[T]) OrFirst(vs ...Option[T]) Option[T]
- func (t Option[T]) OrLast(vs ...Option[T]) Option[T]
- func (t Option[T]) String() string
- func (t *Option[T]) UnmarshalJSON(data []byte) error
- func (t *Option[T]) UnmarshalYAML(unmarshal func(interface{}) error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option[T any] struct { // contains filtered or unexported fields }
Option[T] is a container for zero or one element of a given type.
func Of ¶
Of[T] creates a Option[T] that may or may not have a value. If *T is nil the returned Option[T] is empty (equivalent to None[T]), If *T is non-nil returned Option[T] will contain a value (equivalent to Some[T]).
This is an alias for Option[T]
func (Option[T]) Defined ¶
Defined returns true if the contained value is not empty, false otherwise
Inverse of Empty()
func (Option[T]) Empty ¶
Empty returns true if the contained value is empty, false otherwise
Inverse of Defined()
func (Option[T]) Get ¶
func (t Option[T]) Get() T
Get returns the contained value.
NOTE: If called and Empty() is true, the value will be the type's zero value.
func (Option[T]) MarshalJSON ¶
MarshalJSON implements the encoding/json#Marshaler interface
func (Option[T]) MarshalYAML ¶
MarshalYAML implements the gopkg.in/yaml.v2#Marshal interface
func (Option[T]) OrElse ¶
func (t Option[T]) OrElse(v T) T
OrElse returns the contained value if Defined() is true or returns the provided argument.
func (Option[T]) OrFirst ¶
OrFirst returns the contained value if Defined() is true or returns the first item from the provided list which is Defined().
func (Option[T]) OrLast ¶
OrLast returns the contained value if Defined() is true or returns the first item from the provided list which is Defined() starting from the last value in the provided list.
func (*Option[T]) UnmarshalJSON ¶
UnmarshalJSON implements the encoding/json#Unmarshaler interface
func (*Option[T]) UnmarshalYAML ¶
UnmarshalYAML implements the gopkg.in/yaml.v2#Unmarshal interface