Skip to content
Advertisement

flatMap reuse response from reactive call

Currently, I have a question, something like this:

JavaScript

User

JavaScript

X

JavaScript

Y

JavaScript

The question is how do I reuse correctly the “user” and the “x” response from the previous call?

Here are my solutions for marked(*) place:

  1. nested flatMap(), then can thenReturn(user) for next map().

Any issue with the scope of a variable(user) when I build a chain(nested flatMap…) like this so far?

JavaScript
  1. keep response by wrapping it in an object using map (i don’t want to use this solution)
JavaScript

X1, wrap x and user

JavaScript

any idea, please help to review/advice Thank you

Advertisement

Answer

This question is very opinionated.

i would personally use a zipWith operator which merges the results of 2 monos into a tuple.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement