Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flatMap #18

Open
innermatrix opened this issue Jan 24, 2024 · 2 comments
Open

flatMap #18

innermatrix opened this issue Jan 24, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@innermatrix
Copy link

Please explain the feature or improvement you would like:

Please add async flatMap

Please describe the use case where you would need that feature (the general situation or type of program where that would be helpful):

Currently the best counterpart to

arr.flatMap((elt) => f(elt))

is

(await asyncMap(arr, async (elt) => await f(elt))).flatMap(elt => elt)

Which is janky. I would prefer

await asyncFlatMap(arr, async (elt) => await f(elt))

Please explain why you think that feature would be helpful to other people:

Because flatMap is in stdlib Array

@innermatrix innermatrix added the enhancement New feature or request label Jan 24, 2024
@nicolas-van
Copy link
Owner

nicolas-van commented Jan 25, 2024

Actually you should also be able to call

await asyncMap(arr, async (elt) => await f(elt)).flat()

which is a bit shorter.

But yes, it is true that we could provide a shorthand with asyncFlatMap.

@innermatrix
Copy link
Author

Good point 🤦 but yes please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants