Documentation ¶
Index ¶
- type Optional
- func (o Optional) Else(elseValue T) (value T)
- func (o Optional) ElseFunc(f func() T) (value T)
- func (o Optional) ElseZero() (value T)
- func (o Optional) Get() (value T, ok bool)
- func (o Optional) If(f func(value T))
- func (o Optional) IsPresent() bool
- func (o Optional) MarshalJSON() (data []byte, err error)
- func (o Optional) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Optional) String() string
- func (o *Optional) UnmarshalJSON(data []byte) error
- func (o *Optional) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Optional ¶
type Optional optional
Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.
func OfOptionalPtr ¶
func (Optional) Else ¶
Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.
func (Optional) ElseZero ¶
ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.
func (Optional) Get ¶
Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.
func (Optional) MarshalJSON ¶
MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Optional) MarshalXML ¶
MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.
func (Optional) String ¶
String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.
func (*Optional) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.
func (*Optional) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a value wrapped by this optional.