writeIterable<T> method

void writeIterable <T>(
  1. List<T> target,
  2. int at,
  3. Iterable<T> source
)

Write the elements of an iterable into a list.

This is a utility function that can be used to implement methods like setAll.

The elements of source are written into target from position at. The source must not contain more elements after writing the last position of target.

If the source is a list, the copyRange function is likely to be more efficient.

Implementation

static void writeIterable<T>(List<T> target, int at, Iterable<T> source) {
  RangeError.checkValueInInterval(at, 0, target.length, "at");
  int index = at;
  int targetLength = target.length;
  for (var element in source) {
    if (index == targetLength) {
      throw IndexError(targetLength, target);
    }
    target[index] = element;
    index++;
  }
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-core/List/writeIterable.html