Documentation ¶
Index ¶
- type Elastic
- func Defined[T any](v []nullable.Nullable[T]) Elastic[T]
- func FromMultiple[T any](v []T) Elastic[T]
- func FromMultiplePointer[T any](v *[]T) Elastic[T]
- func FromSingle[T any](v T) Elastic[T]
- func FromSinglePointer[T any](v *T) Elastic[T]
- func Null[T any]() Elastic[T]
- func Undefined[T any]() Elastic[T]
- func (e Elastic[T]) Equal(other Elastic[T]) bool
- func (e Elastic[T]) First() jsonfield.JsonField[T]
- func (e *Elastic[T]) IsMultiple() bool
- func (e *Elastic[T]) IsNull() bool
- func (e *Elastic[T]) IsNullish() bool
- func (e *Elastic[T]) IsSingle() bool
- func (f Elastic[T]) MarshalJSON() ([]byte, error)
- func (e Elastic[T]) PlainMultiple() []*T
- func (e Elastic[T]) PlainSingle() *T
- func (b *Elastic[T]) UnmarshalJSON(data []byte) error
- func (e Elastic[T]) ValueMultiple() []T
- func (e Elastic[T]) ValueSingle() T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Elastic ¶
type Elastic[T any] struct { undefinedable.Undefinedable[[]nullable.Nullable[T]] }
An overly elastic type where it can be `undefined | (null | T) | (null | T)[]`.
func FromMultiple ¶
FromMultiple returns Elastic[T] that contains multiple T values.
func FromMultiplePointer ¶
FromMultiplePointer converts *[]T to Elastic[T]. If v is nil, returns a defined but empty Elastic[T].
func FromSingle ¶
FromSingle returns Elastic[T] that contains a single T value.
func FromSinglePointer ¶
FromSinglePointer converts *T to Elastic[T]. If v is nil, returns a defined but empty Elastic[T].
func (*Elastic[T]) IsMultiple ¶
func (*Elastic[T]) IsNull ¶
IsNull returns true when e is a single null value, returns false otherwise.
func (*Elastic[T]) IsNullish ¶
IsNullish returns true when it is considered empty, namely `undefined | null | null[]` or empty `T[]`. It returns false otherwise.
func (Elastic[T]) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
MarshalJSON encodes f into a json format. It always marshalls defined to be []T, undefined to be null.
func (Elastic[T]) PlainMultiple ¶
func (e Elastic[T]) PlainMultiple() []*T
PlainMultiple returns slice of []*T. It returns always a non-nil even if e is undefined.
func (Elastic[T]) PlainSingle ¶
func (e Elastic[T]) PlainSingle() *T
PlainSingle returns a first value of e as *T, the plain conventional Go representation of an optional value. If e is undefined or has no value, then it returns nil.
func (*Elastic[T]) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
UnmarshalJSON accepts null, T and (null | T)[].
Caveats: Do not hold references to any underlying data. UnmarshalJSON may swap its internal value.
func (Elastic[T]) ValueMultiple ¶
func (e Elastic[T]) ValueMultiple() []T
ValueMultiple returns []T, replacing null value with zero value of T.
func (Elastic[T]) ValueSingle ¶
func (e Elastic[T]) ValueSingle() T
ValueSingle returns a first value of e. If e is nullish, namely `undefined | null | null[]` or empty `T[]`, it returns zero value of T.