In RxJava, how to pass a variable along when chaining observables?

I asked the question on stackoverflow, if anyone here want to chime in:

In RxJava, how to pass a variable along when chaining observables?

I believe you would have to use tuples: http://docs.couchbase.com/sdk-api/couchbase-core-io-1.0.1/com/couchbase/client/core/lang/Tuple.html

You can use tuples (or value objects), but most of the time its better to use flatMap and use an “inner observable” instead of dragging the data along.

Can you give us a specific example of what you want to do?

Here is my use case: I have a View that is a secondary index and return documents keys, I do a ViewQuery(secondary_index) and flatmap the result to a function that fetch the actual documents. I want to be able to access the value of “secondary_index” down the chain for logging & error handling.

@ldoguin ok thanks, I believe using a Tuple is similar to the stackoverflow solution that uses Pair.

I imagine a value object is a custom object that I’d design to contain all the values I want to pass along.

@daschl I didn’t think about an inner observable, it feels less readable than chaining stuff but I see it can work. Maybe I’ll try that.