interleaveFactory method
Returns a lazy iterable that inserts a separator between every pair of
adjacent elements, using separatorFactory to produce each one.
separatorFactory is called once per gap, so it can return a fresh
instance each time — useful when the separator is a widget that must not
be reused.
Example:
[1, 2, 3].interleaveFactory(() => 0).toList(); // [1, 0, 2, 0, 3]
The returned iterable is lazy: separatorFactory is not invoked until
the iterable is consumed. If the source contains fewer than two elements,
no separator is produced.
Implementation
Iterable<T> interleaveFactory(T Function() separatorFactory) {
return Iterable.withIterator(
() => _InterleaveIterator(iterator, separatorFactory),
);
}