Documentation
¶
Index ¶
- type Map
- func (om *Map[K, V]) All() iter.Seq2[K, V]
- func (om *Map[K, V]) Delete(key K)
- func (om *Map[K, V]) Get(key K) (V, bool)
- func (om *Map[K, V]) Has(key K) bool
- func (om *Map[K, V]) Keys() []K
- func (om *Map[K, V]) Len() int
- func (om *Map[K, V]) MarshalJSON() ([]byte, error)
- func (om *Map[K, V]) MarshalYAML() (any, error)
- func (om *Map[K, V]) Set(key K, val V)
- func (om *Map[K, V]) UnmarshalJSON(data []byte) error
- func (om *Map[K, V]) UnmarshalYAML(node *yaml.Node) error
- func (om *Map[K, V]) Values() []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map is an ordered map that maintains insertion order of keys while providing O(1) key access through an internal map.
func (*Map[K, V]) All ¶ added in v0.5.0
All returns an iterator over key-value pairs in insertion order. This allows using the map with range loops:
for k, v := range m.All() {
fmt.Printf("%v: %v\n", k, v)
}
func (*Map[K, V]) Delete ¶
func (om *Map[K, V]) Delete(key K)
Delete removes the key-value pair from the map.
func (*Map[K, V]) Get ¶
Get returns the value for the given key and true if it exists, or the zero value and false if it doesn't.
func (*Map[K, V]) Keys ¶ added in v0.5.0
func (om *Map[K, V]) Keys() []K
Keys returns a slice of all keys in insertion order.
func (*Map[K, V]) MarshalJSON ¶
MarshalJSON implements json.Marshaler interface to marshal an ordered map into a JSON object.
func (*Map[K, V]) MarshalYAML ¶
MarshalYAML implements yaml.Marshaler interface to marshal an ordered map into a YAML object.
func (*Map[K, V]) Set ¶
func (om *Map[K, V]) Set(key K, val V)
Set sets the value for the given key. If the key already exists, it updates the value without changing the order. If the key is new, it appends the key to the end.
func (*Map[K, V]) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler interface to unmarshal a JSON object into an ordered map. Nested objects are automatically converted to ordered maps.
func (*Map[K, V]) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler interface to unmarshal a YAML object into an ordered map. Nested objects are automatically converted to ordered maps.