Code-Memo

Functools-style patterns

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)
Sorting
import "sort"

sort.Ints(xs)
sort.Slice(people, func(i, j int) bool {
	return people[i].Age < people[j].Age
})
Partial application

Return a closure:

func add(a int) func(int) int {
	return func(b int) int { return a + b }
}
Memoization

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.Once

Initialize once (like a lazy singleton without races).

Pipelines

Chain functions explicitly; readability beats clever one-liners.