public static <T> Stream<List<? extends T>> splitListToChunks(@NotNull List<? extends T> list, int chunkSize) {
    if (chunkSize <= 0) {
      throw new IllegalArgumentException("invalid chunkSize: " + chunkSize);
    }
    int listSize = list.size();
    if (listSize == 0) {
      return Stream.empty();
    }
    int numberOfChunks = listSize / chunkSize;
    return IntStream.range(0, numberOfChunks * chunkSize == listSize ? numberOfChunks : numberOfChunks + 1)
      .mapToObj(i -> list.subList(i * chunkSize, Math.min(listSize, i * chunkSize + chunkSize)));
  }
public static <T> Stream<List<? extends T>> splitListToChunks(@NotNull List<? extends T> list, int chunkSize)