traverseListWithIndex<A, B> static method

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

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

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

Implementation

static IOOption<List<B>> traverseListWithIndex<A, B>(
  List<A> list,
  IOOption<B> Function(A a, int i) f,
) =>
    IOOption<List<B>>(
      () => Option.sequenceList(
        IO
            .traverseListWithIndex<A, Option<B>>(
              list,
              (a, i) => IO(() => f(a, i).run()),
            )
            .run(),
      ),
    );