Documentation
¶
Index ¶
- func Equal[T comparable](l, r Option[T]) bool
- func EqualFunc[L, R any](l Option[L], r Option[R], fn func(l L, r R) bool) bool
- type Noneable
- type Option
- func (o Option[T]) Get() T
- func (o Option[T]) GetOr(value T) T
- func (o Option[T]) GetOrFunc(getter func() T) T
- func (o Option[T]) GetOrZero() T
- func (o Option[T]) GoString() string
- func (o Option[T]) IsNone() bool
- func (o Option[T]) IsSome() bool
- func (o Option[T]) IsZero() bool
- func (o Option[T]) LogValue() slog.Value
- func (o Option[T]) MarshalJSON() (b []byte, err error)
- func (it *Option[T]) Scan(value any) (err error)
- func (o Option[T]) String() string
- func (o *Option[T]) UnmarshalJSON(b []byte) (err error)
- func (it *Option[T]) Value() (driver.Value, error)
- type Someable
- type Zeroable
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Equal ¶ added in v1.0.2
func Equal[T comparable](l, r Option[T]) bool
Types ¶
type Option ¶
type Option[T any] struct { // contains filtered or unexported fields }
Example (States) ¶
var value Option[string] fmt.Println("value is zero, same as undefined:", value.IsZero()) value = None[string]() fmt.Println("value is none, defined and same as null:", value.IsNone()) value = Some[string]("hello world") fmt.Println("value is some, defined and not null:", value.IsSome())
Output: value is zero, same as undefined: true value is none, defined and same as null: true value is some, defined and not null: true
func (Option[T]) Get ¶
func (o Option[T]) Get() T
Get returns a value if it some, in other case panics.
func (Option[T]) GetOr ¶
func (o Option[T]) GetOr(value T) T
GetOr returns the value if the option is none.
Example ¶
fmt.Println("none", None[int]().GetOr(1)) fmt.Println("some", Some(2).GetOr(1)) fmt.Println("zero", Option[int]{}.GetOr(3))
Output: none 1 some 2 zero 3
func (Option[T]) GetOrFunc ¶
func (o Option[T]) GetOrFunc(getter func() T) T
GetOrFunc retunrs value from getter if the option is none
Example ¶
fmt.Println("none", None[int]().GetOrFunc(func() int { return 1 })) fmt.Println("some", Some(2).GetOrFunc(func() int { return 1 })) fmt.Println("zero", Option[int]{}.GetOrFunc(func() int { return 3 }))
Output: none 1 some 2 zero 3
func (Option[T]) GetOrZero ¶
func (o Option[T]) GetOrZero() T
GetOrZero returns the zero value if the option is none.
Example ¶
fmt.Println("none", None[int]().GetOrZero()) fmt.Println("some", Some(1).GetOrZero()) fmt.Println("zero", Option[int]{}.GetOrZero())
Output: none 0 some 1 zero 0
func (Option[T]) MarshalJSON ¶
MarshalJSON is a implementation of the json.Marshaler.
func (*Option[T]) UnmarshalJSON ¶
UnmarshalJSON is a implementation of the json.Unmarshaler.
Click to show internal directories.
Click to hide internal directories.