Canonical guidance

Use when

Avoid

Preferred pattern

func Index[S ~[]E, E comparable](s S, v E) int {
	for i := range s {
		if s[i] == v {
			return i
		}
	}
	return -1
}

Anti-pattern

Explanation: This anti-pattern is tempting after learning generics, but abstraction without repeated use makes APIs harder to read without reducing real duplication.

Why

Sources