optional: 4d63.com/optional/template Index | Files

package template

import "4d63.com/optional/template"

Index

Package Files

optional.go

type Optional Uses

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 Empty Uses

func Empty() Optional

Empty returns an empty optional.

func Of Uses

func Of(value T) Optional

Of wraps the value in an optional.

func OfOptionalPtr Uses

func OfOptionalPtr(ptr *T) Optional

func (Optional) Else Uses

func (o Optional) Else(elseValue T) (value T)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Optional) ElseFunc Uses

func (o Optional) ElseFunc(f func() T) (value T)

func (Optional) ElseZero Uses

func (o Optional) ElseZero() (value T)

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 Uses

func (o Optional) Get() (value T, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Optional) If Uses

func (o Optional) If(f func(value T))

If calls the function if there is a value wrapped by this optional.

func (Optional) IsPresent Uses

func (o Optional) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Optional) MarshalJSON Uses

func (o Optional) MarshalJSON() (data []byte, err error)

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 Uses

func (o Optional) MarshalXML(e *xml.Encoder, start xml.StartElement) error

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 Uses

func (o Optional) String() 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 Uses

func (o *Optional) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Optional) UnmarshalXML Uses

func (o *Optional) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type T Uses

type T string

Package template imports 4 packages (graph). Updated 2018-10-03. Refresh now. Tools for package owners.