Documentation
¶
Index ¶
- func MapOrElseOption[T, U any](o Option[T], defaultFn func() U, f func(T) U) U
- func MapOrOption[T, U any](o Option[T], defaultValue U, f func(T) U) U
- type Cloner
- type Equality
- type Option
- func FlattenOption[T any](o Option[Option[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 MapOption[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 (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]) CheckUnd() error
- func (o Option[T]) Clone() Option[T]
- func (o Option[T]) Equal(other Option[T]) bool
- 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]) MarshalJSON() ([]byte, error)
- func (o Option[T]) MarshalJSONV2(enc *jsontext.Encoder, opts jsonv2.Options) 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]) UnmarshalJSON(data []byte) error
- func (o *Option[T]) UnmarshalJSONV2(dec *jsontext.Decoder, opts jsonv2.Options) error
- func (o *Option[T]) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- func (o Option[T]) ValidateUnd() 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 MapOrElseOption ¶
MapOrElseOption returns value o's value applied by f if o is some. Otherwise it returns a defaultFn result.
func MapOrOption ¶
MapOrOption returns o's value applied by f if o is some. Otherwise it returns defaultValue.
Types ¶
type Option ¶
type Option[T any] struct { // contains filtered or unexported fields }
Option represents an optional value.
func FlattenOption ¶
FlattenOption converts Option[Option[T]] into Option[T].
func GetMap ¶
func GetMap[M ~map[K]V, K comparable, V any](m M, key K) Option[V]
func MapOption ¶
MapOption returns Some[U] whose inner value is o's value mapped by f if o is Some. Otherwise it returns None[U].
func (Option[T]) Equal ¶
Equal implements Equality[Option[T]].
Equal tests o and other if both are Some or None. If both have value, it tests equality of their values.
Equal panics If T or dynamic type of T is not comparable.
Option is comparable if T is comparable. Equal only exists for cases where T needs a special Equal method (e.g. time.Time, slice based types)
Equal first checks if T implements Equality[T], then also for *T. If it does not, then Equal compares by the `==` comparison operator.
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]) MarshalJSON ¶
func (Option[T]) MarshalJSONV2 ¶
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]) UnmarshalJSON ¶
func (*Option[T]) UnmarshalJSONV2 ¶
func (*Option[T]) UnmarshalXML ¶
func (Option[T]) ValidateUnd ¶
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.