traverseListWithIndex<A, B> static method

IO<List<B>> traverseListWithIndex<A, B>(
  1. List<A> list,
  2. IO<B> f(
    1. A a,
    2. int i
    )
)

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

Same as IO.traverseList but passing index in the map function.

Implementation

static IO<List<B>> traverseListWithIndex<A, B>(
  List<A> list,
  IO<B> Function(A a, int i) f,
) =>
    IO<List<B>>(() {
      final resultList = <B>[];
      for (var i = 0; i < list.length; i++) {
        resultList.add(f(list[i], i).run());
      }
      return resultList;
    });