zipWith<U, R> method

Option<R> zipWith<U, R>(
  1. Option<U> other,
  2. R combine(
    1. T left,
    2. U right
    )
)

Combines this value with other's, when both are present.

combine is not called unless both are present.

final sum = const Some<int>(1).zipWith(const Some<int>(2), (a, b) => a + b);

Implementation

Option<R> zipWith<U, R>(
    Option<U> other, R Function(T left, U right) combine) {
  return switch ((this, other)) {
    (Some<T>(value: final left), Some<U>(value: final right)) =>
      Some<R>(combine(left, right)),
    _ => None<R>(),
  };
}