intersperse method
Creates a new Iterable with the separator interposed between elements.
If beforeFirst
is true, the separator is prepended to the iterable (if
it has at least one element).
If afterLast
is true, the separator is appended to the iterable (if it
has at least one element).
Implementation
Iterable<A> intersperse(
A item, {
bool beforeFirst = false,
bool afterLast = false,
}) sync* {
final iterator = this.iterator;
if (iterator.moveNext()) {
if (beforeFirst) {
yield item;
}
yield iterator.current;
while (iterator.moveNext()) {
yield item;
yield iterator.current;
}
if (afterLast) {
yield item;
}
}
}