pair
Combine parallel slices without index math.
Slices must be equal length — these are parallel data, not ragged collections. Pair[A, B] holds two values, accessed via .First and .Second.
pairs := pair.Zip(names, scores) // []Pair[string, int]
What It Looks Like
// Zip and iterate
for _, p := range pair.Zip(names, ages) {
fmt.Printf("%s is %d\n", p.First, p.Second)
}
// Transform while zipping
users := pair.ZipWith(names, ages, NewUser)
Operations
Of[A, B](A, B) Pair[A, B] — create a pair
Zip[A, B]([]A, []B) []Pair[A, B] — combine slices into pairs
ZipWith[A, B, R]([]A, []B, func(A, B) R) []R — combine and transform
Zip and ZipWith panic if slice lengths differ.
See pkg.go.dev for complete API documentation, the main README for installation, and slice.Unzip for the inverse operation.