lens @ 6531b1c0a720a63ee3127f9a09f14ba861838b01

 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
32	return chuncks
33}
34
35func Zip[T, U any](left []T, right []U) []Pair[T, U] {
36	// pick the array with the smaller length
37	l := len(left)
38	if len(left) > len(right) {
39		l = len(right)
40	}
41
42	pairs := make([]Pair[T, U], len(left))
43	for i := 0; i < l; i++ {
44		pairs[i] = Pair[T, U]{left[i], right[i]}
45	}
46	return pairs
47}
48
49func Revert[T any](s []T) {
50	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
51		s[i], s[j] = s[j], s[i]
52	}
53}