Documentation ¶
Index ¶
- func Iterate[K comparable, V any](ctx context.Context, m *Map[K, V]) <-chan Pair[K, V]
- func Len[K comparable, V any](m *Map[K, V]) int
- type Map
- func Cast[K comparable, V any](v any) *Map[K, V]
- func From[K comparable, V any](iter iter.Seq2[K, V]) *Map[K, V]
- func FromPairs[K comparable, V any](pairs ...Pair[K, V]) *Map[K, V]
- func New[K comparable, V any]() *Map[K, V]
- func SortAlpha[K comparable, V any](m *Map[K, V]) *Map[K, V]
- func ToOrderedMap[K comparable, V any](m map[K]V) *Map[K, V]
- func (o *Map[K, V]) FindValueUntyped(key string) any
- func (o *Map[K, V]) First() Pair[K, V]
- func (o *Map[K, V]) FromNewest() iter.Seq2[K, V]
- func (o *Map[K, V]) FromOldest() iter.Seq2[K, V]
- func (o *Map[K, V]) GetKeyType() reflect.Type
- func (o *Map[K, V]) GetOrZero(k K) V
- func (o *Map[K, V]) GetValueType() reflect.Type
- func (o *Map[K, V]) IsZero() bool
- func (o *Map[K, V]) KeysFromNewest() iter.Seq[K]
- func (o *Map[K, V]) KeysFromOldest() iter.Seq[K]
- func (o *Map[K, V]) ToYamlNode(n NodeBuilder, l any) *yaml.Node
- func (o *Map[K, V]) ValuesFromNewest() iter.Seq[V]
- func (o *Map[K, V]) ValuesFromOldest() iter.Seq[V]
- type MapToYamlNoder
- type NodeBuilder
- type Pair
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Map ¶
type Map[K comparable, V any] struct { *wk8orderedmap.OrderedMap[K, V] }
Map represents an ordered map where the key must be a comparable type, the ordering is based on insertion order.
func From ¶ added in v0.17.0
func From[K comparable, V any](iter iter.Seq2[K, V]) *Map[K, V]
From creates a new ordered map from an iterator.
func FromPairs ¶
func FromPairs[K comparable, V any](pairs ...Pair[K, V]) *Map[K, V]
FromPairs creates an `OrderedMap` from an array of pairs. Use `NewPair()` to generate input parameters.
func SortAlpha ¶
func SortAlpha[K comparable, V any](m *Map[K, V]) *Map[K, V]
SortAlpha sorts the map by keys in alphabetical order.
func ToOrderedMap ¶
func ToOrderedMap[K comparable, V any](m map[K]V) *Map[K, V]
ToOrderedMap converts a `map` to `OrderedMap`.
func (*Map[K, V]) FindValueUntyped ¶
FindValueUntyped finds a value in the ordered map by key if the stored value for that key implements GetValueUntyped otherwise just returns the value.
func (*Map[K, V]) FromNewest ¶ added in v0.17.0
FromNewest returns an iterator that yields the newest key-value pair in the map.
func (*Map[K, V]) FromOldest ¶ added in v0.17.0
FromOldest returns an iterator that yields the oldest key-value pair in the map.
func (*Map[K, V]) GetKeyType ¶
GetKeyType returns the reflection type of the key.
func (*Map[K, V]) GetOrZero ¶
func (o *Map[K, V]) GetOrZero(k K) V
GetOrZero will return the value for the key if it exists, otherwise it will return the zero value for the value type.
func (*Map[K, V]) GetValueType ¶
GetValueType returns the reflection type of the value.
func (*Map[K, V]) KeysFromNewest ¶ added in v0.17.0
KeysFromNewest returns an iterator that yields the newest key in the map.
func (*Map[K, V]) KeysFromOldest ¶ added in v0.17.0
FromNewest returns an iterator that yields the newest key-value pair in the map.
func (*Map[K, V]) ToYamlNode ¶
func (o *Map[K, V]) ToYamlNode(n NodeBuilder, l any) *yaml.Node
ToYamlNode converts the ordered map to a yaml node ready for marshalling.
func (*Map[K, V]) ValuesFromNewest ¶ added in v0.17.0
ValuesFromNewest returns an iterator that yields the newest value in the map.
func (*Map[K, V]) ValuesFromOldest ¶ added in v0.17.0
ValuesFromOldest returns an iterator that yields the oldest value in the map.
type MapToYamlNoder ¶
type MapToYamlNoder interface {
ToYamlNode(n NodeBuilder, l any) *yaml.Node
}
type NodeBuilder ¶
type Pair ¶
type Pair[K comparable, V any] interface { Key() K KeyPtr() *K Value() V ValuePtr() *V Next() Pair[K, V] }
Pair represents a key/value pair in an ordered map returned for iteration.
func First ¶
func First[K comparable, V any](m *Map[K, V]) Pair[K, V]
First returns map's first pair for iteration. Safely handles nil pointer.
func NewPair ¶
func NewPair[K comparable, V any](key K, value V) Pair[K, V]
NewPair instantiates a `Pair` object for use with `FromPairs()`.