Python’s functools (partial, reduce, lru_cache) has Go analogues without one package name.
cmp and slices (Go 1.21+)import "cmp"
import "slices"
first := slices.Min([]int{3, 1, 4})
idx := slices.BinarySearch(xs, target)
_ = cmp.Compare(a, b)
import "sort"
sort.Ints(xs)
sort.Slice(people, func(i, j int) bool {
return people[i].Age < people[j].Age
})
Return a closure:
func add(a int) func(int) int {
return func(b int) int { return a + b }
}
Use map with mutex, or sync.Map for read-heavy caches — or a tiny generic helper. No stdlib LRU — use github.com/hashicorp/golang-lru when eviction matters.
sync.OnceInitialize once (like a lazy singleton without races).
Chain functions explicitly; readability beats clever one-liners.