package moslice func Batch[T any](ts []T, size int) [][]T { if len(ts) == 0 || size <= 0 { return nil } numBatches := (len(ts) + size - 1) / size batches := make([][]T, 0, numBatches) for i := 0; i < len(ts); i += size { end := i + size if end > len(ts) { end = len(ts) } batches = append(batches, ts[i:end]) } return batches }