Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PairsToMap ¶
func PairsToMap[K comparable, V any](pairs []Pair[K, V]) map[K]V
PairsToMap converts a []Pair[K, V] to a map[K]V. In case of duplicate keys, the last value will be used.
func Sort ¶
func Sort[K comparable, V any](pairs []Pair[K, V])
Sort sorts a list of Pairs alphabetically by their keys. The sort happens in-place. Note that this uses the Compare method, which may panic if the keys are not comparable.
func SortStable ¶
func SortStable[K comparable, V any](pairs []Pair[K, V])
SortStable sorts a list of Pairs alphabetically by their keys. The sort happens in-place and is stable. Note that this uses the Compare method, which may panic if the keys are not comparable.
Types ¶
type Comparable ¶
type Pair ¶
type Pair[K comparable, V any] struct { Key K Value V }
Pair is a generic key-value pair.
func MapToPairs ¶
func MapToPairs[K comparable, V any](pairs map[K]V) []Pair[K, V]
MapToPairs converts a map[K]V to a []Pair[K, V]. Note that the order of of the list is arbitrary.
func New ¶
func New[K comparable, V any](key K, value V) Pair[K, V]
New creates a new Pair with the given key and value.