flatAndCollect<T, X> method

Future<Response<List<T>>> flatAndCollect<T, X>(
  1. Iterable<X> source,
  2. Response<T> mapper(
    1. X source
    )
)

Implementation

Future<Response<List<T>>> flatAndCollect<T, X>(
  Iterable<X> source,
  Response<T> Function(X source) mapper,
) async {
  var res = await this;
  if (res.isError) return Responses.failure<List<T>>(res.errors);
  var response = Responses.success<List<T>>([]);
  for (var id in source) {
    response = response.flatMap((tab) => mapper(id).map((t) => tab!.appendInPlace(t!)));
  }
  return response;
}