tryReduce method

T? tryReduce(
  1. T combine(
    1. T,
    2. T
    )
)

Tries to reduce the iterable, returning null if the iterable is empty.

Exceptions thrown by combine (including Error subclasses such as StackOverflowError) propagate to the caller — only the StateError("No element") from reducing an empty iterable is caught.

Implementation

T? tryReduce(T Function(T, T) combine) {
  if (isEmpty) return null;
  return reduce(combine);
}