maybeAsyncCombine<T> method

FutureOr<Maybe<T>> maybeAsyncCombine<T>({
  1. FutureOr<Maybe<T>> firstJust(
    1. K
    )?,
  2. FutureOr<Maybe<T>> secondJust(
    1. J
    )?,
  3. FutureOr<Maybe<T>> bothJust(
    1. K,
    2. J
    )?,
  4. FutureOr<Maybe<T>> bothNothing()?,
})

Use it to asynchronously combine two different Maybe's into a new one. Input firstJust to map case where only the first value is Just, secondJust to map case where only the second value is Just, bothJust to map case where both first and second value are Just and bothNothing to map case where both are Nothing Example:


    Maybe<Number> combined = await (testString, testInt).maybeAsyncCombine<Number>(
      bothJust: (val, number) async => await ...,
      firstJust: (val) async => await ...,
      secondJust: (number) async => await ...,
      bothNothing: () async => await ....,
    );


Implementation

FutureOr<Maybe<T>> maybeAsyncCombine<T>({
  /// Used to map case where only the first value is [Just]
  FutureOr<Maybe<T>> Function(K)? firstJust,

  /// Used to map case where only the second value is [Just]
  FutureOr<Maybe<T>> Function(J)? secondJust,

  /// Used to map case where both values are [Just]
  FutureOr<Maybe<T>> Function(K, J)? bothJust,

  /// Used to map case where both values are [Nothing]
  FutureOr<Maybe<T>> Function()? bothNothing,
}) {
  return $1.when(
    nothing: () => $2.when(
      nothing: () => bothNothing != null ? bothNothing() : Nothing<T>(),
      just: (J secondData) =>
          secondJust != null ? secondJust(secondData) : Nothing<T>(),
    ),
    just: (firstData) => $2.when(
      nothing: () => firstJust != null ? firstJust(firstData) : Nothing<T>(),
      just: (J secondData) =>
          bothJust != null ? bothJust(firstData, secondData) : Nothing<T>(),
    ),
  );
}