merge<M, J> method

Result<M, E> merge<M, J>(
  1. Result<J, E> other,
  2. M onJoin(
    1. T,
    2. J
    )
)

Performs a merge operation and returns a new instance of M.

Implementation

Result<M, E> merge<M, J>(Result<J, E> other, M Function(T, J) onJoin) =>
    match(
      onSuccess: (firstValue) => other.match(
        onSuccess: (secondValue) =>
            Success<M, E>(onJoin(firstValue, secondValue)),
        onError: Error<M, E>.new,
      ),
      onError: (firstError) => other.match(
        onSuccess: (_) => Error<M, E>(firstError),
        onError: (_) => Error<M, E>(firstError),
      ),
    );