pair
Combine parallel slices without index math.
Slices must be equal length — these are parallel data, not ragged collections. X[V1, V2] holds two values, accessed via .V1 and .V2.
pairs := pair.Zip(names, scores) // []X[string, int]
What It Looks Like
// Zip and iterate
for _, p := range pair.Zip(names, ages) {
fmt.Printf("%s is %d\n", p.V1, p.V2)
}
// Transform while zipping
users := pair.ZipWith(names, ages, NewUser)
Operations
Of[V1, V2](V1, V2) X[V1, V2] — create a pair
Zip[V1, V2]([]V1, []V2) []X[V1, V2] — 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.