joinElements method

Iterable<T> joinElements(
  1. T separator
)

Interleaves the given separator item between the elements of this iterable.

The separator will only be inserted between two of this iterable's elements. If there is only one item in this iterable, of if the iterable is empty, the separator will not be inserted.

Implementation

Iterable<T> joinElements(T separator) sync* {
  var hasEmitted = false;

  for (final item in this) {
    if (hasEmitted) yield separator;
    yield item;
    hasEmitted = true;
  }
}