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

thenCombine vs thenCompose #347

Open
cherylchan02 opened this issue Nov 29, 2022 · 3 comments
Open

thenCombine vs thenCompose #347

cherylchan02 opened this issue Nov 29, 2022 · 3 comments

Comments

@cherylchan02
Copy link

cherylchan02 commented Nov 29, 2022

Both of these methods are used to combine 2 completable futures asynchronously, but I'm not very sure what differentiates them and which method to use in what circumstance. Would appreciate if someone could explain this thanks!

@valerietanhx
Copy link

I believe thenCompose is used if you want to compose two Futures, so the output of one becomes the input of the other. On the other hand, thenCombine is used if you want to put together both the outputs of each Future.

e.g. bar(foo(a)) --> thenCompose, but bar(a) + foo(a) --> thenCombine

CMIIW!

@sumhungyee
Copy link

sumhungyee commented Nov 29, 2022

thenCombine is similar to thenApply but uses a Bifunction instead. thenCompose is similar to flatmap, thenApply is map

@mohddanesh
Copy link

agree with @sumhungyee. comparing it to map will make it easier to understand

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

4 participants