separatedBy method

Iterable<E> separatedBy(
  1. E separator(
    1. int index
    )
)

Introduces a separator between all elements of the iterable.

The separator can be dynamically adjusted for each call.

Implementation

Iterable<E> separatedBy(E Function(int index) separator) sync* {
  int index = -1;
  for (var item in this) {
    if (index != -1) yield separator(index);
    yield item;
    ++index;
  }
}