cycleList<T> function

List<T> cycleList<T>(
  1. int n,
  2. Iterable<T> it
)

Repeat elements of a list n times

Implementation

List<T> cycleList<T>(int n, Iterable<T> it) {
  List<T> l = List.from(it);
  if (n <= 0) {
    return [];
  }

  List<T> result = [];
  for (int j = 0; j < n; j++) {
    for (int i = 0; i < l.length; i++) {
      result.add(l[i]);
    }
  }

  return result;
}