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.
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 new IndexError(targetLength, target); } target[index] = element; index++; } }
© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/2.0.0/dart-core/List/writeIterable.html