tryMerge method

Iterable<T>? tryMerge([
  1. Iterable<T> merge(
    1. Iterable<T>?,
    2. Iterable<T>?
    )?
])

Tries to merge the iterables, returning null if it fails.

Implementation

Iterable<T>? tryMerge([
  Iterable<T> Function(Iterable<T>?, Iterable<T>?)? merge,
]) {
  try {
    return reduce(merge ?? (a, b) => <T>[...a ?? [], ...b ?? []]);
  } catch (_) {
    return null;
  }
}