Just a gotcha: neither ReScript nor your JS engine will optimize it. While synchronous recursive functions can be optimized by ReScript into a JS while loop, asynchronous functions can not.
But there are optimizations in V8 and other runtimes to handle await calls in loops.
So you should prefer that instead:
let iterAsyncFor: (array<'a>, 'a => promise<'b>) => promise<array<'b>> = async (
arr,
fn,
) => {
let result = []
for v in 0 to arr->Array.length - 1 {
result[v] = await fn(arr->Array.getUnsafe(v))
}
result
}