tryInsert8 method

Iterable<T> tryInsert8(
  1. int index,
  2. T v1,
  3. T v2,
  4. T v3,
  5. T v4,
  6. T v5,
  7. T v6,
  8. T v7,
  9. T v8,
)

Inserts eight elements into the iterable at the specified index.

Takes the specified elements and inserts it into the iterable at the position index.

If index is less than zero, a RangeError is thrown.

If iteration of this iterable is exausted before the position index is reached, the given elements are not inserted and this iterable is unchanged.

Implementation

Iterable<T> tryInsert8(
  int index,
  T v1,
  T v2,
  T v3,
  T v4,
  T v5,
  T v6,
  T v7,
  T v8,
) sync* {
  if (index == 0) {
    yield* prepend8(v1, v2, v3, v4, v5, v6, v7, v8);
    return;
  }
  if (index < 0) {
    throw RangeError.index(
      index,
      this,
      'index',
      'Parameter "index" must be greater than or equal to zero.',
    );
  }

  final iterator = this.iterator;
  var i = 0;

  while (iterator.moveNext()) {
    if (i == index) {
      yield v1;
      yield v2;
      yield v3;
      yield v4;
      yield v5;
      yield v6;
      yield v7;
      yield v8;
    }
    yield iterator.current;
    i++;
  }
}