func Batches[T any](a []T, batchSize int) [][]T {
	if len(a) == 0 {
		return [][]T{}
	}

	batches := make([][]T, 0, (len(a)+batchSize-1)/batchSize)

	for batchSize < len(a) {
		a, batches = a[batchSize:], append(batches, a[0:batchSize:batchSize])
	}
	batches = append(batches, a)

	return batches
}
// Batches returns batches of a with maximum size batchSize while performing minimal allocations. All elements in a will
// be returned in a batch - the last batch may be smaller than batchSize.
Batches returns batches of a with maximum size batchSize while performing minimal allocations. All elements in a will
be returned in a batch - the last batch may be smaller than batchSize.
// Batches returns batches of a with maximum size batchSize while performing minimal allocations . All elements in a will // be returned in a batch - the last batch may be smaller than batchSize .
func Batches[T any](a []T, batchSize int) [][]T {
	if len(a) == 0 {
		return [][]T{}
	}
	batches := make([][]T, 0, (len(a)+batchSize-1)/batchSize)
	for batchSize < len(a) {
		a, batches = a[batchSize:], append(batches, a[0:batchSize:batchSize])
	}
	batches = append(batches, a)
	return batches
}
func Batches [ T any ] ( a [ ] T , batchSize int ) [ ] [ ] T { if len ( a ) == 0 { return [ ] [ ] T { } } batches := make ( [ ] [ ] T , 0 , ( len ( a ) + batchSize - 1 ) / batchSize ) for batchSize < len ( a ) { a , batches = a [ batchSize : ] , append ( batches , a [ 0 : batchSize : batchSize ] ) } batches = append ( batches , a ) return batches }
Batches returns batches of a with maximum size batchSize while performing minimal allocations.
Batches returns batches of a with maximum size batchSize while performing minimal allocations .