omap

package
v3.38.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OrderedMap

type OrderedMap[K cmp.Ordered, V any] struct {
	// contains filtered or unexported fields
}

An OrderedMap is a wrapper around a regular map that maintains an ordered list of the map's keys. This allows you to run deterministic and ordered operations on the map such as printing/serializing/iterating.

func FromMap

func FromMap[K cmp.Ordered, V any](m map[K]V) OrderedMap[K, V]

FromMap will create a new OrderedMap from the given map. Since Golang maps are unordered, the order of the created OrderedMap will be random.

func FromMapWithOrder

func FromMapWithOrder[K cmp.Ordered, V any](m map[K]V, order []K) OrderedMap[K, V]

func New

func New[K cmp.Ordered, V any]() OrderedMap[K, V]

New will create a new OrderedMap of the given type and return it.

func (*OrderedMap[K, V]) DeepCopy

func (om *OrderedMap[K, V]) DeepCopy() OrderedMap[K, V]

func (*OrderedMap[K, V]) Exists

func (om *OrderedMap[K, V]) Exists(key K) bool

Exists will return whether or not the given key exists.

func (*OrderedMap[K, V]) Get

func (om *OrderedMap[K, V]) Get(key K) V

Get will return the value for a given key. If the key does not exist, it will return the zero value of the value type.

func (*OrderedMap[K, V]) Keys

func (om *OrderedMap[K, V]) Keys() []K

Keys will return a slice of the map's keys in order.

func (*OrderedMap[K, V]) Len

func (om *OrderedMap[K, V]) Len() int

Len will return the number of items in the map.

func (*OrderedMap[K, V]) Merge

func (om *OrderedMap[K, V]) Merge(other OrderedMap[K, V])

Merge merges the given Vars into the caller one

func (*OrderedMap[K, V]) Range

func (om *OrderedMap[K, V]) Range(fn func(key K, value V) error) error

Range will iterate over the map and call the given function for each key/value.

func (*OrderedMap[K, V]) Set

func (om *OrderedMap[K, V]) Set(key K, value V)

Set will set the value for a given key.

func (*OrderedMap[K, V]) Sort

func (om *OrderedMap[K, V]) Sort()

Sort will sort the map.

func (*OrderedMap[K, V]) SortFunc

func (om *OrderedMap[K, V]) SortFunc(less func(i, j K) int)

SortFunc will sort the map using the given function.

func (*OrderedMap[K, V]) UnmarshalYAML

func (om *OrderedMap[K, V]) UnmarshalYAML(node *yaml.Node) error

func (*OrderedMap[K, V]) Values

func (om *OrderedMap[K, V]) Values() []V

Values will return a slice of the map's values in order.

Jump to

Keyboard shortcuts

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