lens @ a87e03ac1b777be4169f0d27c69e17505d96802b

 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 Distribuite[T any](slice []T, size int) [][]T {
17	chuncks := make([][]T, size)
18
19	for i := 0; i < len(slice); i += size {
20		for x := 0; x < size; x++ {
21			end := i + x
22
23			if end >= len(slice) {
24				return chuncks
25			}
26
27			chuncks[x] = append(chuncks[x], slice[end])
28		}
29	}
30
31	return chuncks
32}
33
34func Zip[T, U any](left []T, right []U) []Pair[T, U] {
35	// pick the array with the smaller length
36	l := len(left)
37	if len(left) > len(right) {
38		l = len(right)
39	}
40
41	pairs := make([]Pair[T, U], len(left))
42	for i := 0; i < l; i++ {
43		pairs[i] = Pair[T, U]{left[i], right[i]}
44	}
45	return pairs
46}
47
48func Revert[T any](s []T) {
49	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
50		s[i], s[j] = s[j], s[i]
51	}
52}