merge<T> function

Iterable<T> merge<T>(
  1. Iterable<Iterable<T>> iterables, [
  2. Comparator<T>? compare
])

Returns the result of merging an Iterable of Iterables, according to the order specified by the compare function. This function assumes the provided iterables are already sorted according to the provided compare function. It will not check for this condition or sort the iterables.

The compare function must act as a Comparator. If compare is omitted, Comparable.compare is used.

If any of the iterables contain null elements, an exception will be thrown.

Implementation

Iterable<T> merge<T>(Iterable<Iterable<T>> iterables,
    [Comparator<T>? compare]) {
  if (iterables.isEmpty) return <T>[];
  if (iterables.every((i) => i.isEmpty)) return <T>[];
  return _Merge<T>(iterables, compare ?? _compareAny);
}