cerrado @ aa559681fcf8df993029370f28e0011315ca8761

 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 LastOrZero[T any](v []T) T {
20	if len(v) == 0 {
21		var zero T
22		return zero
23	}
24	return v[len(v)-1]
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}