pipeAsync<T2> method

Future<Result<T2>> pipeAsync<T2>(
  1. Future f(
    1. T
    )
)

If result is Err then returns this Err as is. If result is Ok then returns result of call await f(result.val). If result of call f() is null - returns Err('function returned null'). If result of call f() is Result - returns it as is. If call of f() throws exception, then returns Err.

Implementation

Future<Result<T2>> pipeAsync<T2>(Future Function(T) f) async {
  if (isErr) {
    return Err<T2>(err);
  }
  var argument = unwrap;
  var res = await f(argument);
  if (res == null) {
    return Err<T2>(
        StateError('Result of f($argument) == null, where `f` is $f'));
  } else {
    if (res is Error) {
      return Err<T2>(res);
    } else {
      if (res is Ok) {
        return Ok(res.unwrap);
      } else if (res is Err) {
        return Err<T2>(res.err);
      } else {
        return Ok(res);
      }
    }
  }
}