intersperse<T> function

Iterable<T> intersperse<T>(
  1. T element,
  2. Iterable<T> iterable
)

courtesy of @modulovalue (https://github.com/modulovalue/dart_intersperse/blob/master/lib/src/intersperse.dart) intersperses elements in between list items - used to insert dividers between toolbar buttons when using ToolbarType.nativeScrollable

Implementation

Iterable<T> intersperse<T>(T element, Iterable<T> iterable) sync* {
  final iterator = iterable.iterator;
  if (iterator.moveNext()) {
    yield iterator.current;
    while (iterator.moveNext()) {
      yield element;
      yield iterator.current;
    }
  }
}