package u func Filter[T any](v []T, f func(T) bool) []T { var result []T for _, s := range v { if f(s) { result = append(result, s) } } return result } func First[T any](v []T) (T, bool) { if len(v) == 0 { var zero T return zero, false } return v[0], true } func FirstOrZero[T any](v []T) T { if len(v) == 0 { var zero T return zero } return v[0] } func LastOrZero[T any](v []T) T { if len(v) == 0 { var zero T return zero } return v[len(v)-1] } func ChunkBy[T any](items []T, chunkSize int) [][]T { chunks := make([][]T, 0, (len(items)/chunkSize)+1) for chunkSize < len(items) { items, chunks = items[chunkSize:], append(chunks, items[0:chunkSize:chunkSize]) } return append(chunks, items) }