cerrado @ 6b96b76d66a929a2b428505809fda23a19005c63

 1package u
 2
 3func First[T any](v []T) (T, bool) {
 4	if len(v) == 0 {
 5		var zero T
 6		return zero, false
 7	}
 8	return v[0], true
 9}
10
11func FirstOrZero[T any](v []T) T {
12	if len(v) == 0 {
13		var zero T
14		return zero
15	}
16	return v[0]
17}
18
19func Map[T any, V any](ts []T, fun func(T) V) []V {
20	rs := make([]V, len(ts))
21	for i := range ts {
22		rs[i] = fun(ts[i])
23	}
24	return rs
25}
26
27func ChunkBy[T any](items []T, chunkSize int) [][]T {
28	var chunks = make([][]T, 0, (len(items)/chunkSize)+1)
29	for chunkSize < len(items) {
30		items, chunks = items[chunkSize:], append(chunks, items[0:chunkSize:chunkSize])
31	}
32	return append(chunks, items)
33}