countAndReplace method
Implementation
Iterable<T> countAndReplace(T target, T Function(int count) replacer) sync* {
Iterator<T> iterator = this.iterator;
int count = 0;
while (iterator.moveNext()) {
T element = iterator.current;
if (element == target) {
count++;
} else {
if (count > 0) {
yield replacer(count);
count = 0;
}
yield element;
}
}
if (count > 0) {
yield replacer(count);
}
}