Documentation
¶
Index ¶
- func ByIndex[M ~map[K]V, K comparable, V any](m M, getIndex func(V) int) iter.Seq2[K, V]
- func MarshalJSONTo[M ByIndexer[K, V], K comparable, V any](m M, enc *jsontext.Encoder, opts json.Options) error
- func Set[M ~map[K]V, K comparable, V any](m *M, key K, v V, getIndex func(V) int, setIndex func(V, int) V)
- func Sort[M ~map[K]V, K cmp.Ordered, V any](m M, setIndex func(V, int) V)
- func SortFunc[M ~map[K]V, K comparable, V any](m M, setIndex func(V, int) V, less func(K, K) int)
- func UnmarshalJSONFrom[M ~map[K]R, K comparable, R any](m *M, dec *jsontext.Decoder, opts json.Options, setIndex func(R, int) R) error
- type ByIndexer
- type OrderedMap
- func (om OrderedMap[K, V]) ByIndex() iter.Seq2[K, V]
- func (om *OrderedMap[_, _]) MarshalJSONTo(enc *jsontext.Encoder, opts json.Options) error
- func (om *OrderedMap[K, V]) Set(key K, v V)
- func (om OrderedMap[K, V]) Sort(less func(K, K) int)
- func (om *OrderedMap[K, V]) UnmarshalJSONFrom(dec *jsontext.Decoder, opts json.Options) error
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByIndex ¶
func ByIndex[M ~map[K]V, K comparable, V any](m M, getIndex func(V) int) iter.Seq2[K, V]
ByIndex is a helper function for an ordered map to implement an iterator.
func MarshalJSONTo ¶
func MarshalJSONTo[M ByIndexer[K, V], K comparable, V any]( m M, enc *jsontext.Encoder, opts json.Options, ) error
MarshalJSONTo marshals an ordered map by encoding its key-value pairs in order.
func Set ¶
func Set[M ~map[K]V, K comparable, V any]( m *M, key K, v V, getIndex func(V) int, setIndex func(V, int) V, )
Set is a helper function to set a value in the map, adding it at the end of the order.
func SortFunc ¶
func SortFunc[M ~map[K]V, K comparable, V any](m M, setIndex func(V, int) V, less func(K, K) int)
SortFunc is a helper function to sort a map by key using a custom comparison function and set the indices accordingly.
func UnmarshalJSONFrom ¶
func UnmarshalJSONFrom[M ~map[K]R, K comparable, R any]( m *M, dec *jsontext.Decoder, opts json.Options, setIndex func(R, int) R, ) error
UnmarshalJSONFrom is a helper function to unmarshal an ordered map setting the indices in order.
Types ¶
type ByIndexer ¶
type ByIndexer[K comparable, V any] interface { // ByIndex returns a sequence of key-value pairs sorted by index. ByIndex() iter.Seq2[K, V] }
ByIndexer is an interface for an ordered map that implements an iterator.
type OrderedMap ¶
type OrderedMap[K comparable, V any] map[K]Value[V]
OrderedMap is a map that can be ordered.
func (OrderedMap[K, V]) ByIndex ¶
func (om OrderedMap[K, V]) ByIndex() iter.Seq2[K, V]
ByIndex returns a sequence of key-value pairs sorted by index.
func (*OrderedMap[_, _]) MarshalJSONTo ¶
MarshalJSONTo marshals the key-value pairs in order.
func (*OrderedMap[K, V]) Set ¶
func (om *OrderedMap[K, V]) Set(key K, v V)
Set sets a value in the map, adding it at the end of the order.
func (OrderedMap[K, V]) Sort ¶
func (om OrderedMap[K, V]) Sort(less func(K, K) int)
Sort sorts the map by key using a custom comparison function and sets the indices accordingly.
func (*OrderedMap[K, V]) UnmarshalJSONFrom ¶
UnmarshalJSONFrom unmarshals the key-value pairs in order and sets the indices.
type Value ¶
type Value[V any] struct { V V // contains filtered or unexported fields }
Value is a value with an index.
func (Value[_]) MarshalJSONTo ¶
MarshalJSONTo marshals a value by encoding just the value and ignoring the index.