mapOrElse<U> method

Result<U, E> mapOrElse<U>(
  1. U onOk(
    1. T value
    ),
  2. U onErr(
    1. E error
    )
)

If it's Ok, apply the function to the value; otherwise, return the original Result.

Implementation

Result<U, E> mapOrElse<U>(
  U Function(T value) onOk,
  U Function(E error) onErr,
) {
  if (this is Ok<T, E>) {
    return Ok(onOk((this as Ok<T, E>).value));
  }
  return Err((this as Err<T, E>).error);
}