splice method

Vec<T> splice(
  1. int start,
  2. int end,
  3. Iterable<T> replaceWith
)

Creates a splicing iterator that replaces the specified range in the vector with the given replaceWith iterator and yields the removed items. replace_with does not need to be the same length as range.

Implementation

// Dev Note: For the real functionality, we would need to implement a custom iterator that removes the section, then
// adds items from [replaceWith] as it iterates over it, but this may end up being more computationally
// expensive than just doing it eagerly.
Vec<T> splice(int start, int end, Iterable<T> replaceWith) {
  final range = getRange(start, end).toList(growable: false);
  replaceRange(start, end, replaceWith);
  return range;
}