insertOrAppend3 method

Iterable<T> insertOrAppend3(
  1. int index,
  2. T v1,
  3. T v2,
  4. T v3,
)

Inserts three 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, an ArgumentError is thrown.

If iteration of the underlying iterable is exausted before the position index is reached, the elements are added to the end iterable as if calling append.

Implementation

Iterable<T> insertOrAppend3(int index, T v1, T v2, T v3) sync* {
  if (index == 0) {
    yield* prepend3(v1, v2, v3);
    return;
  }
  if (index < 0) {
    throw ArgumentError('Parameter "index" must be greater than zero.');
  }

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

  while (iterator.moveNext()) {
    if (i == index) {
      yield v1;
      yield v2;
      yield v3;
    }
    yield iterator.current;
    i++;
  }

  if (index >= i) {
    yield v1;
    yield v2;
    yield v3;
  }
}