transpose method

Result<T, E>? transpose()

Transposes a Result with a nullable value into a nullable Result.

Ok(null) will be mapped to null. Ok(v) and Err(e) (if v and e are not null) will be returned as is.

Implementation

Result<T, E>? transpose() {
  if (isOk) {
    final x = unwrap();
    return x != null ? Ok(x) : null;
  } else {
    return Err(unwrapErr());
  }
}