Documentation
¶
Index ¶
- type Elastic
- func FromOptions[Opts ~[]option.Option[T], T any](options Opts) Elastic[T]
- func FromPointer[T any](t *T) Elastic[T]
- func FromPointers[T any](ps []*T) Elastic[T]
- func FromValue[T any](t T) Elastic[T]
- func FromValues[T any](ts []T) Elastic[T]
- func Null[T any]() Elastic[T]
- func Undefined[T any]() Elastic[T]
- func (e Elastic[T]) Clone() Elastic[T]
- func (e Elastic[T]) Equal(other Elastic[T]) bool
- func (e Elastic[T]) IsDefined() bool
- func (e Elastic[T]) IsNull() bool
- func (e Elastic[T]) IsUndefined() bool
- func (e Elastic[T]) IsZero() bool
- func (o Elastic[T]) LogValue() slog.Value
- func (e Elastic[T]) Map(f func(und.Und[option.Options[T]]) und.Und[option.Options[T]]) Elastic[T]
- func (u Elastic[T]) MarshalJSON() ([]byte, error)
- func (e Elastic[T]) MarshalJSONV2(enc *jsontext.Encoder, opts jsonv2.Options) error
- func (o Elastic[T]) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (e Elastic[T]) Pointer() *T
- func (e Elastic[T]) Pointers() []*T
- func (e *Elastic[T]) UnmarshalJSON(data []byte) error
- func (o *Elastic[T]) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- func (e Elastic[T]) Unwrap() und.Und[option.Options[T]]
- func (e Elastic[T]) Value() T
- func (e Elastic[T]) Values() []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Elastic ¶
type Elastic[T any] struct { // contains filtered or unexported fields }
Elastic[T] is a type that can express undefined | null | T | [](null | T). Elastic[T] is comparable if T is comparable. And it can be copied by assign.
Elastic[T] implements IsZero and can be skippable struct fields when marshaled through appropriate marshalers, e.g. "github.com/go-json-experiment/json/jsontext" with omitzero option set to the field, or "github.com/json-iterator/go" with omitempty option to the field and an appropriate extension.
If you need to stick with encoding/json v1, you can use github.com/ngicks/und/sliceund/elastic, a slice based version of Elastic[T] whish is already skppable by v1.
func FromOptions ¶
FromOptions converts slice of option.Option[T] into Elastic[T]. options is retained by the returned value.
func FromPointer ¶
FromPointer converts nil to undefined Elastic[T], or defined one whose internal value is dereferenced t.
func FromPointers ¶
FromPointers converts []*T into an Elastic[T], treating nil as None[T], and non-nil as Some[T].
func FromValues ¶
FromValues converts []T into an Elastic[T].
func (Elastic[T]) Clone ¶
Clone implements option.Cloner[Elastic[T]].
Clone clones its internal option.Option slice by copy. Or if T implements Cloner[T], each element is cloned.
func (Elastic[T]) Equal ¶
Equal implements option.Equality[Elastic[T]].
Equal panics if T is uncomparable.
func (Elastic[T]) IsDefined ¶
IsDefined returns true if e is a defined Elastic[T], which includes a slice with no element.
func (Elastic[T]) IsUndefined ¶
IsUndefined returns true if e is an undefined Elastic[T].
func (Elastic[T]) Map ¶
Map returns a new Elastic[T] whose internal value is e's mapped by f.
The internal slice of e is capped to its length before passed to f.
func (Elastic[T]) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Elastic[T]) MarshalJSONV2 ¶
MarshalJSONV2 implements jsonv2.MarshalerV2.
func (Elastic[T]) MarshalXML ¶
MarshalXML implements xml.Marshaler.
func (Elastic[T]) Pointer ¶
func (e Elastic[T]) Pointer() *T
Pointer returns a first value of its internal option slice as *T if e is defined.
Pointer returns nil if
- e is not defined
- e has no element
- e's first element is None.
func (Elastic[T]) Pointers ¶
func (e Elastic[T]) Pointers() []*T
Pointer returns its internal option slice as []*T if e is defined.
func (*Elastic[T]) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Elastic[T]) UnmarshalXML ¶
UnmarshalXML implements xml.Unmarshaler.