lens @ f99f2bc94808d784c92ec4e58c660a8be3ed7fce

 1package list
 2
 3func Map[V any, T any](source []V, fun func(V) T) []T {
 4	result := make([]T, 0, len(source))
 5	for _, s := range source {
 6		result = append(result, fun(s))
 7	}
 8	return result
 9}
10
11type Pair[T, U any] struct {
12	Left  T
13	Right U
14}
15
16func Zip[T, U any](left []T, right []U) []Pair[T, U] {
17	// pick the array with the smaller length
18	l := len(left)
19	if len(left) > len(right) {
20		l = len(right)
21	}
22
23	pairs := make([]Pair[T, U], len(left))
24	for i := 0; i < l; i++ {
25		pairs[i] = Pair[T, U]{left[i], right[i]}
26	}
27	return pairs
28}
29
30func Revert[T any](s []T) {
31	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
32		s[i], s[j] = s[j], s[i]
33	}
34}