Documentation
¶
Index ¶
- Variables
- type OrderedMap
- func (om *OrderedMap[K, V]) Count() int
- func (om *OrderedMap[K, V]) Delete(key K)
- func (om *OrderedMap[K, V]) Has(key K) bool
- func (om *OrderedMap[K, V]) Keys() []K
- func (om *OrderedMap[K, V]) KeysValues() ([]K, []V)
- func (om *OrderedMap[K, V]) MarshalJSON() ([]byte, error)
- func (om *OrderedMap[K, V]) Set(key K, value V)
- func (om *OrderedMap[K, V]) UnmarshalJSON(data []byte) error
- func (om *OrderedMap[K, V]) Value(key K) (V, bool)
- func (om *OrderedMap[K, V]) Values() []V
Constants ¶
This section is empty.
Variables ¶
var ErrKeysMustBeStrings = fmt.Errorf("keys must be strings")
Functions ¶
This section is empty.
Types ¶
type OrderedMap ¶
type OrderedMap[K comparable, V any] struct { // contains filtered or unexported fields }
OrderedMap wraps around a Go map keeping the order with which elements have been added. Keys must be comparable, but values can be anything. Unlike map, index assigment is not possible. Use the `Set` method to set a key with a particular value. Use the Keys method to retrieves keys, Values to get the values. To get both, which probably what you want, use the KeysValues method.
func NewOrderedMap ¶
func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V]
func (*OrderedMap[K, V]) Count ¶
func (om *OrderedMap[K, V]) Count() int
Count returns the number of elements in the map.
func (*OrderedMap[K, V]) Delete ¶
func (om *OrderedMap[K, V]) Delete(key K)
Delete deletes the element with the specified key from the OrderedMap.
func (*OrderedMap[K, V]) Has ¶
func (om *OrderedMap[K, V]) Has(key K) bool
Has returns whether the map contains key.
func (*OrderedMap[K, V]) Keys ¶
func (om *OrderedMap[K, V]) Keys() []K
Keys returns keys as slice of string.
func (*OrderedMap[K, V]) KeysValues ¶
func (om *OrderedMap[K, V]) KeysValues() ([]K, []V)
KeysValues returns the keys as slice of strings, and values as slice of interfaces.
func (*OrderedMap[K, V]) MarshalJSON ¶
func (om *OrderedMap[K, V]) MarshalJSON() ([]byte, error)
func (*OrderedMap[K, V]) Set ¶
func (om *OrderedMap[K, V]) Set(key K, value V)
Set key in OrderedMap to value. Previously stored values are overwritten, but the order does not change.
func (*OrderedMap[K, V]) UnmarshalJSON ¶
func (om *OrderedMap[K, V]) UnmarshalJSON(data []byte) error
func (*OrderedMap[K, V]) Value ¶
func (om *OrderedMap[K, V]) Value(key K) (V, bool)
Value returns the value for key and also whether it was found. The bool is returned because value could be nil.
func (*OrderedMap[K, V]) Values ¶
func (om *OrderedMap[K, V]) Values() []V
Values returns the values as slice of interfaces.