Documentation ¶
Index ¶
- type Option
- func (o Option[T]) Get() (res T, ok bool)
- func (o Option[T]) GetOrElse(defaultValue T) (res T)
- func (o Option[T]) IsNone() bool
- func (o Option[T]) IsSome() bool
- func (o Option[T]) MarshalJSON() ([]byte, error)
- func (o *Option[T]) Scan(value interface{}) error
- func (o *Option[T]) UnmarshalJSON(data []byte) error
- func (o Option[T]) Unwrap() (res T)
- func (o Option[T]) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶ added in v1.0.1
type Option[T any] struct { // contains filtered or unexported fields }
Option is a generic type that can be used to represent a value that may or may not be present.
func None ¶
None returns an Option[T] with no value. Example:
opt := None() fmt.Println(opt.IsNone()) // true
func Some ¶
Some returns an Option[T] with a value. Example:
opt := Some(42) fmt.Println(opt.IsSome()) // true
func (Option[T]) Get ¶ added in v1.1.0
Get returns the value of the Options[T] and a boolean indicating if the value is present. Example:
opt := Some(42) val, ok := opt.Get() fmt.Println(val, ok) // 42, true
func (Option[T]) GetOrElse ¶ added in v1.1.0
func (o Option[T]) GetOrElse(defaultValue T) (res T)
GetOrElse returns the value of the Options[T]. If the Options[T] has no value, it returns the default value. Example:
opt := Some(42) fmt.Println(opt.GetOrElse(0)) // 42
func (Option[T]) IsNone ¶ added in v1.0.1
IsNone returns true if the Options[T] has no value. Example:
opt := None() fmt.Println(opt.IsNone()) // true
func (Option[T]) IsSome ¶ added in v1.0.1
IsSome returns true if the Options[T] has a value. Example:
opt := Some(42) fmt.Println(opt.IsSome()) // true
func (Option[T]) MarshalJSON ¶ added in v1.1.1
MarshalJSON implements the json.Marshaler interface.
func (*Option[T]) UnmarshalJSON ¶ added in v1.1.1
UnmarshalJSON implements the json.Unmarshaler interface.