orderedmap

package
v0.16.6 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: MIT Imports: 9 Imported by: 25

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

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