interleaveList<T> function

List<T> interleaveList<T>(
  1. Iterable<T> it1,
  2. Iterable<T> it2
)

Join two iterables by taking turns.

Implementation

List<T> interleaveList<T>(Iterable<T> it1, Iterable<T> it2) {
  List<T> copy1 = List.from(it1);
  List<T> copy2 = List.from(it2);
  List<T> result = [];

  int minLength = min(copy1.length, copy2.length);
  for (int i = 0; i < minLength; i++) {
    result
      ..add(copy1[i])
      ..add(copy2[i]);
  }
  return result += copy1.sublist(minLength) + copy2.sublist(minLength);
}