package fmtsort

import "internal/fmtsort"

Package fmtsort provides a general stable ordering mechanism for maps, on behalf of the fmt and text/template packages. It is not guaranteed to be efficient and works only for types that are valid map keys.

Index

Types

type KeyValue

type KeyValue struct {
	Key, Value reflect.Value
}

KeyValue holds a single key and value pair found in a map.

type SortedMap

type SortedMap []KeyValue

SortedMap is a slice of KeyValue pairs that simplifies sorting and iterating over map entries.

Each KeyValue pair contains a map key and its corresponding value.

func Sort

func Sort(mapValue reflect.Value) SortedMap

Sort accepts a map and returns a SortedMap that has the same keys and values but in a stable sorted order according to the keys, modulo issues raised by unorderable key values such as NaNs.

The ordering rules are more general than with Go's < operator:

Source Files

sort.go

Version
v1.23.0-rc.2
Published
Jul 16, 2024
Platform
js/wasm
Imports
3 packages
Last checked
21 seconds ago

Tools for package owners.