Support async functions for Array.prototype

What happens?

I had experience with functional JavaScript. One problem that I have is none of the array method supports to get async function as a parameter. Example:

array2 = => await doSomething(item))

What the problem?

But I can not able to write await keyword in the non-asynchrony function or if I make function inside asynchrony it returns a promise and my array filled the promises not values. I did not find any possible solution to how I can solve this problem in a functional style and finally rewrite it into a loop.

Why it important?

In my perfect world, programmers are able to generate asynchrony array/objects and get real results instead of promises.

What I suggest?

I am not sure how it should work but I have an idea. Array can have a duplication of existing functions that will be retunded value from resolved promises:

array2 = array1.asyncMap(async (item) => doSomething(item))

Or add support to 'then' block in arrow functions that returns a promise:

array2 = => doSomething(item).then(result => result.value)

const array2 = await Promise.all( ?

1 Like

Oh.. Thank you