package eu.mhsl.minecraft.pixelblocks.utils;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class ListUtil {
    public static <T> List<List<T>> splitListInParts(int parts, List<T> list) {
        int actualParts = Math.min(parts, list.size());
        int chunkSize = (int) Math.ceil((double) list.size() / actualParts);
        return IntStream.range(0, actualParts)
            .mapToObj(i -> list.stream()
                .skip((long) i * chunkSize)
                .limit(chunkSize)
                .collect(Collectors.toList()))
            .toList();
    }

}
