mapAsync<U> method

Future<Result<U, E>> mapAsync<U>(
  1. Future<U> fn(
    1. T value
    )
)

Maps the value inside Ok asynchronously, keeping Err unchanged.

Implementation

Future<Result<U, E>> mapAsync<U>(Future<U> Function(T value) fn) async {
  if (this is Ok<T, E>) {
    try {
      final result = await fn((this as Ok<T, E>).value);
      return Ok(result);
    } catch (e) {
      return Err(e as E); // Cast carefully or handle the type properly.
    }
  }
  return this as Result<U, E>;
}