package tools

func CutoffChan[T any](c chan T, size int) [][]T {
	var listGroup [][]T
	step := 0
	var curList []T
	for itm := range c {
		if step >= size {
			step = 0
			listGroup = append(listGroup, curList)
			curList = []T{}
		}
		curList = append(curList, itm)
		step++
	}
	if len(curList) > 0 {
		listGroup = append(listGroup, curList)
	}
	return listGroup
}

func CutoffList[T any](c []T, size int) [][]T {
	var listGroup [][]T
	step := 0
	var curList []T
	for _, itm := range c {
		if step >= size {
			step = 0
			listGroup = append(listGroup, curList)
			curList = []T{}
		}
		curList = append(curList, itm)
		step++
	}
	if len(curList) > 0 {
		listGroup = append(listGroup, curList)
	}
	return listGroup
}
