combine2<T1 extends Object, T2 extends Object> static method

Async<(T1, T2)> combine2<T1 extends Object, T2 extends Object>(
  1. Async<T1> a1,
  2. Async<T2> a2, [
  3. @noFutures Err<(T1, T2)> onErr(
    1. Result<T1>,
    2. Result<T2>
    )?
])
override

Combines 2 Async outcomes into 1 containing a tuple of their values if all resolve to Ok.

If any resolve to Err, applies onErr function to combine errors.

See also: combineAsync.

Implementation

static Async<(T1, T2)> combine2<T1 extends Object, T2 extends Object>(
  Async<T1> a1,
  Async<T2> a2, [
  @noFutures Err<(T1, T2)> Function(Result<T1>, Result<T2>)? onErr,
]) {
  final combined = combineAsync<Object>(
    [a1, a2],
    onErr: onErr == null
        ? null
        : (l) => onErr(l[0].transf<T1>(), l[1].transf<T2>()).transfErr(),
  );
  return combined.map((l) => (l[0] as T1, l[1] as T2));
}