Documentation
¶
Index ¶
- func CloneOptions[T comparable, Opts ~[]Option[T]](o Opts) Opts
- func Equal[T comparable](l, r Option[T]) bool
- func EqualOptions[T comparable, Opts ~[]Option[T]](l, r Opts) bool
- func EqualOptionsFunc[T any, Opts ~[]Option[T]](l, r Opts, cmp func(i, j T) bool) bool
- func MapOr[T, U any](o Option[T], defaultValue U, f func(T) U) U
- func MapOrElse[T, U any](o Option[T], defaultFn func() U, f func(T) U) U
- func UndValidate[T validate.UndValidator](o Option[T]) error
- type Option
- func Assert[T any](v any) Option[T]
- func Flatten[T any](o Option[Option[T]]) Option[T]
- func FromOk[T any](t T, ok bool) Option[T]
- func FromPointer[T any](t *T) Option[T]
- func FromSqlNull[T any](v sql.Null[T]) Option[T]
- func GetMap[M ~map[K]V, K comparable, V any](m M, key K) Option[V]
- func GetSlice[S ~[]T, T any](s S, idx int) Option[T]
- func Map[T, U any](o Option[T], f func(T) U) Option[U]
- func None[T any]() Option[T]
- func Some[T any](v T) Option[T]
- func WrapPointer[T any](t *T) Option[*T]
- func (o Option[T]) And(u Option[T]) Option[T]
- func (o Option[T]) AndThen(f func(x T) Option[T]) Option[T]
- func (o Option[T]) CloneFunc(cloneT func(T) T) Option[T]
- func (o Option[T]) EqualFunc(other Option[T], cmp func(i, j T) bool) bool
- func (o Option[T]) Filter(pred func(t T) bool) Option[T]
- func (o Option[T]) Get() (T, bool)
- func (o Option[T]) IsNone() bool
- func (o Option[T]) IsSome() bool
- func (o Option[T]) IsSomeAnd(f func(T) bool) bool
- func (o Option[T]) IsZero() bool
- func (o Option[T]) Iter() iter.Seq[T]
- func (o Option[T]) LogValue() slog.Value
- func (o Option[T]) Map(f func(v T) T) Option[T]
- func (o Option[T]) MapOr(defaultValue T, f func(T) T) T
- func (o Option[T]) MapOrElse(defaultFn func() T, f func(T) T) T
- func (o Option[T]) MapOrElseOpt(defaultFn func() T, f func(T) T) Option[T]
- func (o Option[T]) MapOrOpt(defaultValue T, f func(T) T) Option[T]
- func (o Option[T]) MarshalJSON() ([]byte, error)
- func (o Option[T]) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o Option[T]) Or(u Option[T]) Option[T]
- func (o Option[T]) OrElse(f func() Option[T]) Option[T]
- func (o Option[T]) Plain() *Tdeprecated
- func (o Option[T]) Pointer() *T
- func (o Option[T]) SqlNull() sql.Null[T]
- func (o Option[T]) UndCheck() error
- func (o Option[T]) UndValidate() error
- func (o *Option[T]) UnmarshalJSON(data []byte) error
- func (o *Option[T]) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- func (o Option[T]) Value() T
- func (o Option[T]) Xor(u Option[T]) Option[T]
- type Options
- type SqlNull
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloneOptions ¶
func CloneOptions[T comparable, Opts ~[]Option[T]](o Opts) Opts
func Equal ¶
func Equal[T comparable](l, r Option[T]) bool
Equal tests an equality of l and r then returns true if they are equal, false otherwise
func EqualOptions ¶
func EqualOptions[T comparable, Opts ~[]Option[T]](l, r Opts) bool
EqualOptions tests equality of l and r then returns true if they are equal, false otherwise
func EqualOptionsFunc ¶
EqualOptionsFunc tests equality of l and r using cmp then returns true if they are equal, false otherwise.
func MapOrElse ¶
MapOrElse returns value o's value applied by f if o is some. Otherwise it returns a defaultFn result.
func UndValidate ¶
func UndValidate[T validate.UndValidator](o Option[T]) error
Types ¶
type Option ¶
type Option[T any] struct { // contains filtered or unexported fields }
Option represents an optional value.
func Assert ¶
Assert type-asserts v into T. If v's internal value is T then returns Some of that value, None otherwise.
func FromOk ¶
FromOk converts conventional (t T, ok bool) into an option. The options is some if ok is true, none otherwise.
For getting values from maps or slices, instead you may want to use GetMap, GetSlice respectively.
func FromPointer ¶
FromPointer converts *T into Option[T]. If v is nil, it returns a none Option. Otherwise, it returns some Option whose value is the dereferenced v.
If you need to keep t as pointer, use WrapPointer instead.
func GetMap ¶
func GetMap[M ~map[K]V, K comparable, V any](m M, key K) Option[V]
GetMap gets a value associated with key. If key has a value, the Option is some wrapping the value. Otherwise it returns none Option.
func GetSlice ¶
GetMap gets a value associated with idx. If idx is within interval [0, len(s)), then the Option is some wrapping a value associated to the idx. Otherwise it returns none Option.
func Map ¶
Map returns Some[U] whose inner value is o's value mapped by f if o is Some. Otherwise it returns None[U].
func WrapPointer ¶
WrapPointer converts *T into Option[*T]. The option is some if t is non nil, none otherwise.
If you want t to be dereferenced, use FromPointer instead.
func (Option[T]) EqualFunc ¶
EqualFunc tests o and other if both are Some or None. If their state does not match, it returns false immediately. If both have value, it tests equality of their values by cmp.
func (Option[T]) Filter ¶
Filter returns o if o is some and calling pred against o's value returns true. Otherwise it returns None[T].
func (Option[T]) IsSomeAnd ¶
IsSomeAnd returns true if o is some and calling f with value of o returns true. Otherwise it returns false.
func (Option[T]) Iter ¶
Iter returns an iterator over the internal value. If o is some, the iterator yields the Option.Value(), otherwise nothing.
func (Option[T]) Map ¶
Map returns Option[T] whose inner value is o's value mapped by f if o is some. Otherwise it returns None[T].
func (Option[T]) MapOr ¶
func (o Option[T]) MapOr(defaultValue T, f func(T) T) T
MapOr returns value o's value applied by f if o is some. Otherwise it returns defaultValue.
func (Option[T]) MapOrElse ¶
func (o Option[T]) MapOrElse(defaultFn func() T, f func(T) T) T
MapOrElse returns value o's value applied by f if o is some. Otherwise it returns a defaultFn result.
func (Option[T]) MapOrElseOpt ¶
MapOrElseOpt is like Option.MapOrElse but wraps the returned value into some Option.
func (Option[T]) MapOrOpt ¶
MapOrOpt is like Option.MapOr but wraps the returned value into some Option.
func (Option[T]) MarshalJSON ¶
func (Option[T]) MarshalXML ¶
func (Option[T]) Pointer ¶
func (o Option[T]) Pointer() *T
Pointer transforms o to *T, the plain conventional Go representation of an optional value. The value is copied by assignment before returned from Pointer.
func (Option[T]) UndValidate ¶
func (*Option[T]) UnmarshalJSON ¶
func (*Option[T]) UnmarshalXML ¶
type Options ¶
func (Options[T]) UndValidate ¶
type SqlNull ¶
SqlNull[T] adapts Option[T] to sql.Scanner and driver.Valuer.
func (*SqlNull[T]) Scan ¶
Scan implements sql.Scanner.
If T or *T implements sql.Scanner, the implementation is used. Otherwise, SqlNull[T] falls back to sql.Null[T] as sql.Scanner.