iterutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package iterutil contains determinism-safe iteration helpers.

Go's map iteration order is randomized. Any code that drives output, logging, error reporting, hashing, cache keys, or downstream ordering from a map range produces non-deterministic results across runs.

This package centralizes the "sort then iterate" pattern so authors can opt into determinism explicitly via a single helper, and so a linter (forbidigo or similar) can ban bare `range map[K]V` in determinism-sensitive packages and steer callers here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForEachSorted

func ForEachSorted[K cmp.Ordered, V any](m map[K]V, fn func(K, V))

ForEachSorted invokes fn(key, m[key]) for each key in m, in ascending key order. Callers should prefer this over a bare `for k, v := range m` in any code path that affects observable output, logs, errors, or hashes.

func SortedKeys

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

SortedKeys returns the keys of m in ascending order.

The returned slice is freshly allocated; callers may freely mutate it. For empty maps the returned slice is nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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