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

Add flatMapAsync for Either class #103

Open
jvsoaress opened this issue Mar 25, 2022 · 2 comments
Open

Add flatMapAsync for Either class #103

jvsoaress opened this issue Mar 25, 2022 · 2 comments

Comments

@jvsoaress
Copy link

Sometimes I want to run asynchronous operations inside a .flatMap call. For that I'd suggest adding a .flatMapAsync() method to be able to call await inside the callback function.

I already implemented it in a project I'm working on, so I could open a pr for it as well :)

@spebbe
Copy link
Owner

spebbe commented Mar 28, 2022

Hi @docputs!

Thanks for the suggestion – I agree that something like this would be useful!
Currently, you can use anEitherValue.traverseFuture(asyncComputationEvaluatingToEither).flatMap(id) for this. Adding a traverseFutureM method to Either would get rid of the .flatMap(id) and would then behave like your proposed flatMapAsync. It would also preserve existing naming conventions (like in https://github.com/spebbe/dartz/blob/master/lib/src/ilist.dart#L315) and make it somewhat more explicit that a traversal and a monadic join is happening, rather than just a monadic bind. Does that sound like a reasonable solution to you?

@jvsoaress
Copy link
Author

I didnt get the part where you wrote asyncComputationEvaluatingToEither, because currently the .traverseFuture accepts a callback that returns Future<R2>. In my use case, I need to return a Future<Either<L2, R2>>

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

No branches or pull requests

2 participants