Documentation
¶
Overview ¶
github.com/hauntedness/std/hv is a fork of github.com/samber/mo/option.
Index ¶
- func OrZero[T any](v *T) T
- func Ptr[T any](v T) *T
- type HvOption
- type Option
- func (o Option[T]) Get() (T, bool)
- func (o *Option[T]) GobDecode(data []byte) error
- func (o Option[T]) GobEncode() ([]byte, error)
- func (o Option[T]) IsAbsent() bool
- func (o Option[T]) IsPresent() bool
- func (o Option[T]) IsZero() bool
- func (o Option[T]) MarshalBinary() ([]byte, error)
- func (o Option[T]) MarshalJSON() ([]byte, error)
- func (o Option[T]) MarshalText() ([]byte, error)
- func (o Option[T]) MustGet() T
- func (o Option[T]) OrElse(fallback T) T
- func (o Option[T]) OrEmpty() T
- func (o *Option[T]) Scan(src any) error
- func (o Option[T]) ToPtr() *T
- func (o *Option[T]) UnmarshalBinary(data []byte) error
- func (o *Option[T]) UnmarshalJSON(b []byte) error
- func (o *Option[T]) UnmarshalText(data []byte) error
- func (o Option[T]) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HvOption ¶ added in v0.20.0
type HvOption interface {
// contains filtered or unexported methods
}
HvOption is used to distinguish Option[T] with other types. you may need this in rare corner cases. e.g. when you want to test a reflect.Value is hv.Option. It is hard to instantiate all possible hv.Option[T].
type Option ¶
type Option[T any] struct { // contains filtered or unexported fields }
Option is a container for an optional value of type T. If value exists, Option is of type Some. If the value is absent, Option is of type None.
func (Option[T]) MarshalBinary ¶
MarshalBinary is the interface implemented by an object that can marshal itself into a binary form.
func (Option[T]) MarshalJSON ¶
MarshalJSON encodes Option into json.
func (Option[T]) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (Option[T]) OrElse ¶
func (o Option[T]) OrElse(fallback T) T
OrElse returns value if present or default value.
func (Option[T]) OrEmpty ¶
func (o Option[T]) OrEmpty() T
OrEmpty returns value if present or empty value.
func (Option[T]) ToPtr ¶ added in v0.18.2
func (o Option[T]) ToPtr() *T
ToPtr returns value if present or a nil pointer.
func (*Option[T]) UnmarshalBinary ¶
UnmarshalBinary is the interface implemented by an object that can unmarshal a binary representation of itself.
func (*Option[T]) UnmarshalJSON ¶
UnmarshalJSON decodes Option from json.
func (*Option[T]) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.