hv

package
v0.20.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

github.com/hauntedness/std/hv is a fork of github.com/samber/mo/option.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OrZero

func OrZero[T any](v *T) T

func Ptr added in v0.18.2

func Ptr[T any](v T) *T

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 From added in v0.18.2

func From[T any](value T, ok bool) Option[T]

From builds a Some Option when second argument is true, or None.

func FromPtr added in v0.18.2

func FromPtr[T any](value *T) Option[T]

FromPtr builds a Some Option when value is not nil, or None.

func None

func None[T any]() Option[T]

None builds an Option when value is absent.

func Some

func Some[T any](value T) Option[T]

Some builds an Option when value is present.

func (Option[T]) Get

func (o Option[T]) Get() (T, bool)

Get returns value and presence.

func (*Option[T]) GobDecode

func (o *Option[T]) GobDecode(data []byte) error

GobDecode implements the gob.GobDecoder interface.

func (Option[T]) GobEncode

func (o Option[T]) GobEncode() ([]byte, error)

GobEncode implements the gob.GobEncoder interface.

func (Option[T]) IsAbsent

func (o Option[T]) IsAbsent() bool

IsAbsent returns false when value is present.

func (Option[T]) IsPresent

func (o Option[T]) IsPresent() bool

IsPresent returns false when value is absent.

func (Option[T]) IsZero

func (o Option[T]) IsZero() bool

IsZero support json/v2.

func (Option[T]) MarshalBinary

func (o Option[T]) MarshalBinary() ([]byte, error)

MarshalBinary is the interface implemented by an object that can marshal itself into a binary form.

func (Option[T]) MarshalJSON

func (o Option[T]) MarshalJSON() ([]byte, error)

MarshalJSON encodes Option into json.

func (Option[T]) MarshalText

func (o Option[T]) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Option[T]) MustGet

func (o Option[T]) MustGet() T

MustGet panic if value is not present.

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]) Scan

func (o *Option[T]) Scan(src any) error

Scan implements the SQL sql.Scanner interface.

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

func (o *Option[T]) UnmarshalBinary(data []byte) error

UnmarshalBinary is the interface implemented by an object that can unmarshal a binary representation of itself.

func (*Option[T]) UnmarshalJSON

func (o *Option[T]) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes Option from json.

func (*Option[T]) UnmarshalText

func (o *Option[T]) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Option[T]) Value

func (o Option[T]) Value() (driver.Value, error)

Value implements the driver Valuer interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL