traverseListWithIndexSeq<A, B> static method

Task<List<B>> traverseListWithIndexSeq<A, B>(
  1. List<A> list,
  2. Task<B> f(
    1. A a,
    2. int i

Map each element in the list to a Task using the function f, and collect the result in an Task<List<B>>.

Each Task is executed in sequence. This strategy takes more time than parallel, but it ensures that all the request are executed in order.

If you need Task to be executed in parallel, use traverseListWithIndex.

Same as Task.traverseListSeq but passing index in the map function.


static Task<List<B>> traverseListWithIndexSeq<A, B>(
  List<A> list,
  Task<B> Function(A a, int i) f,
) =>
    Task<List<B>>(() async {
      List<B> collect = [];
      for (var i = 0; i < list.length; i++) {
        collect.add(await f(list[i], i).run());
      return collect;