Help us shape the future of Go! Take the 2026 Go Developer Survey

orderedmap

package
v0.41.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 10 Imported by: 101

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Iterate

func Iterate[K comparable, V any](ctx context.Context, m *Map[K, V]) <-chan Pair[K, V]

Iterate the map in order. Safely handles nil pointer. Be sure to iterate to end or cancel the context when done to release resources.

func Len

func Len[K comparable, V any](m *Map[K, V]) int

Len returns the length of a container implementing a `Len()` method. Safely returns zero on nil pointer.

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 Cast

func Cast[K comparable, V any](v any) *Map[K, V]

Cast converts `any` to `Map`.

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 New

func New[K comparable, V any]() *Map[K, V]

New creates an ordered map generic object.

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

func (o *Map[K, V]) FindValueUntyped(key string) any

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]) First

func (o *Map[K, V]) First() Pair[K, V]

First returns the first pair in the map useful for iteration.

func (*Map[K, V]) FromNewest added in v0.17.0

func (o *Map[K, V]) FromNewest() iter.Seq2[K, V]

FromNewest returns an iterator that yields the newest key-value pair in the map.

func (*Map[K, V]) FromOldest added in v0.17.0

func (o *Map[K, V]) FromOldest() iter.Seq2[K, V]

FromOldest returns an iterator that yields the oldest key-value pair in the map.

func (*Map[K, V]) GetKeyType

func (o *Map[K, V]) GetKeyType() reflect.Type

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

func (o *Map[K, V]) GetValueType() reflect.Type

GetValueType returns the reflection type of the value.

func (*Map[K, V]) IsZero

func (o *Map[K, V]) IsZero() bool

IsZero is required to support `omitempty` tag for YAML/JSON marshaling.

func (*Map[K, V]) KeysFromNewest added in v0.17.0

func (o *Map[K, V]) KeysFromNewest() iter.Seq[K]

KeysFromNewest returns an iterator that yields the newest key in the map.

func (*Map[K, V]) KeysFromOldest added in v0.17.0

func (o *Map[K, V]) KeysFromOldest() iter.Seq[K]

FromNewest returns an iterator that yields the newest key-value pair in the map.

func (*Map[K, V]) MarshalYAML added in v0.38.5

func (o *Map[K, V]) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler for libopenapi's ordered map wrapper.

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

func (o *Map[K, V]) ValuesFromNewest() iter.Seq[V]

ValuesFromNewest returns an iterator that yields the newest value in the map.

func (*Map[K, V]) ValuesFromOldest added in v0.17.0

func (o *Map[K, V]) ValuesFromOldest() iter.Seq[V]

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 NodeBuilder interface {
	AddYAMLNode(parent *yaml.Node, entry *nodes.NodeEntry) *yaml.Node
}

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()`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL