joinElement method
在两个元素之间插入 separator,生成新的迭代器。
separator: 要插入的分隔符。默认为null,即不插入任何分隔符。
返回值:一个新的迭代器,包含插入分隔符后的数据。
Implementation
Iterable<E> joinElement([E? separator]) {
final List<E> result = <E>[];
final Iterator<E> iterator = this.iterator;
if (!iterator.moveNext()) {
return result;
}
if (separator == null) {
do {
result.add(iterator.current);
} while (iterator.moveNext());
} else {
result.add(iterator.current);
while (iterator.moveNext()) {
result.add(separator);
result.add(iterator.current);
}
}
return result;
}