package fmtsort
import "github.com/gohugoio/hugo/tpl/internal/go_templates/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 ¶
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 ¶
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:
- when applicable, nil compares low
- ints, floats, and strings order by <
- NaN compares less than non-NaN floats
- bool compares false before true
- complex compares real, then imag
- pointers compare by machine address
- channel values compare by machine address
- structs compare each field in turn
- arrays compare each element in turn. Otherwise identical arrays compare by length.
- interface values compare first by reflect.Type describing the concrete type and then by concrete value as described in the previous rules.
Source Files ¶
- Version
- v0.144.2 (latest)
- Published
- Feb 19, 2025
- Platform
- linux/amd64
- Imports
- 3 packages
- Last checked
- 13 hours ago –
Tools for package owners.