Documentation
¶
Overview ¶
Package opt implements the Of monad for Go.
Index ¶
- Variables
- type Of
- func (o Of[T]) FlatMap(f func(T) Of[T]) Of[T]
- func (o Of[T]) Fold(onNil func() T, onVal func(T) T) T
- func (o Of[T]) MarshalJSON() ([]byte, error)
- func (o Of[T]) Ptr() *T
- func (o *Of[T]) Scan(src any) error
- func (o *Of[T]) UnmarshalJSON(ba []byte) error
- func (o Of[T]) Unpack() (T, bool)
- func (o Of[T]) Val() T
- func (o Of[T]) Valid() bool
- func (o Of[T]) Value() (driver.Value, error)
- type ScanError
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Of ¶
type Of[T any] struct { // contains filtered or unexported fields }
Of[T] is either a present value (Some) or absent (Nil).
func Morph ¶
Morph maps Of[T] to Of[U] using a function that returns an option. Returns Nil[U] if the option is invalid or if f returns Nil.
func SomeAnyReflect ¶
SomeAnyReflect returns Of[T] using reflection or known interfaces to determine validity. Prefer Some or SomeAny when possible; reflection is 25–50× slower.
func To ¶
To maps Of[T] to Of[U] by applying tf to the value. Returns Nil[U] if the option is invalid.
func (Of[T]) Fold ¶
func (o Of[T]) Fold(onNil func() T, onVal func(T) T) T
Fold returns onVal(t) if valid, otherwise onNil().
func (Of[T]) MarshalJSON ¶
MarshalJSON implements [json.Marshaler]. Marshals the value if valid, otherwise marshals null.
func (*Of[T]) UnmarshalJSON ¶
UnmarshalJSON implements [json.Unmarshaler].