flatMapIndexedTo<R, C extends KtMutableCollection<R>> method

C flatMapIndexedTo<R, C extends KtMutableCollection<R>>(
  1. C destination,
  2. KtIterable<R> transform(
    1. int index,
    2. T
    )
)

Appends all elements yielded from results of transform function being invoked on each element and its index in the original collection, to the given destination.

Implementation

C flatMapIndexedTo<R, C extends KtMutableCollection<R>>(
    C destination, KtIterable<R> Function(int index, T) transform) {
  var index = 0;
  for (final element in iter) {
    final list = transform(index++, element);
    destination.addAll(list);
  }
  return destination;
}