orderedmap

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Examples

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] map[K]V

OrderedMap is a map that can be iterated in the natural order of its keys.

TODO implement json.Marshaler and json.Unmarshaler?

Example
m := OrderedMap[int, string]{}
m[2] = "two"
m[3] = "three"
m[1] = "one"
m[5] = "five"
m[0] = "zero"
m[4] = "four"

m.Iterate(func(k int, v string) bool {
	fmt.Println(v)
	return k != 4
})
Output:

zero
one
two
three
four

func (OrderedMap[K, V]) Iterate

func (m OrderedMap[K, V]) Iterate(iterator func(key K, value V) bool)

Iterate iterates over the keys of the OrderedMap in natural sort order. If the iterator returns false, iteration is aborted (like the break keyword).

Iterate is not safe for concurrent modification.

Jump to

Keyboard shortcuts

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