elastic

package
v0.0.0-...-fd0b456 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2023 License: Apache-2.0 Imports: 4 Imported by: 3

Documentation

Index

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 Defined

func Defined[T any](v []nullable.Nullable[T]) Elastic[T]

func FromMultiple

func FromMultiple[T any](v []T) Elastic[T]

FromMultiple returns Elastic[T] that contains multiple T values.

func FromMultiplePointer

func FromMultiplePointer[T any](v *[]T) Elastic[T]

FromMultiplePointer converts *[]T to Elastic[T]. If v is nil, returns a defined but empty Elastic[T].

func FromSingle

func FromSingle[T any](v T) Elastic[T]

FromSingle returns Elastic[T] that contains a single T value.

func FromSinglePointer

func FromSinglePointer[T any](v *T) Elastic[T]

FromSinglePointer converts *T to Elastic[T]. If v is nil, returns a defined but empty Elastic[T].

func Null

func Null[T any]() Elastic[T]

func Undefined

func Undefined[T any]() Elastic[T]

func (Elastic[T]) Equal

func (e Elastic[T]) Equal(other Elastic[T]) bool

func (Elastic[T]) First

func (e Elastic[T]) First() jsonfield.JsonField[T]

First returns the first value as `undefined | null | T` type.

func (*Elastic[T]) IsMultiple

func (e *Elastic[T]) IsMultiple() bool

func (*Elastic[T]) IsNull

func (e *Elastic[T]) IsNull() bool

IsNull returns true when e is a single null value, returns false otherwise.

func (*Elastic[T]) IsNullish

func (e *Elastic[T]) IsNullish() bool

IsNullish returns true when it is considered empty, namely `undefined | null | null[]` or empty `T[]`. It returns false otherwise.

func (*Elastic[T]) IsSingle

func (e *Elastic[T]) IsSingle() bool

func (Elastic[T]) MarshalJSON

func (f Elastic[T]) MarshalJSON() ([]byte, error)

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

func (b *Elastic[T]) UnmarshalJSON(data []byte) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL