shiftToFirst<T> static method

List<T>? shiftToFirst<T>(
  1. List<T>? list,
  2. int index
)

Shift a list of items from a given index to the first position.

Implementation

static List<T>? shiftToFirst<T>(List<T>? list, int index) {
  if (list == null || list.isEmpty) return list;
  if (index > list.length - 1)
    throw ArgumentError(
        "The shift index can't be bigger than the list size.");
  return list.sublist(index)..addAll(list.sublist(0, index));
}