Passing composite data through flatMap and similar operators without creating container objects
See original GitHub issueTake the following contrived example:
Observable
.just("yo")
.flatMap(s -> Observable.range(0, 100))
.subscribe(integer -> Ln.d("Here's an Integer(%s), but how do I access that juicy String?", integer));
I often come up against this problem, where I’d like to act upon multiple chained streams. I can easily imagine a couple of ways to access both the String Observable and the Integer Observable within a downstream subscribe() or some other operator. One is pulling the String Observable into a variable and then accessing it within a lambda. Another is to do something like:
Observable
.just("yo")
.flatMap(s ->
Observable.combineLatest(
Observable.just(s),
Observable.range(0, 100),
Pair::new))
.subscribe(pair -> Ln.d("Here's an Integer(%s), and here's a juicy String(%s), but isn't this a little hard to follow and annoying?", pair.second, pair.first));
But this necessitates repackaging the original Observable with the dependent Observable into some more complex data structure.
There’s gotta be a better way. Help?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:26
- Comments:22 (10 by maintainers)
Top Results From Across the Web
4. Applying Reactive Programming to Existing Applications
A similar operator, first() , will return a value of T and discard whatever it has left. single() , on the other hand,...
Read more >Passing composite data in rxjs observable chains
You can use a map operator to combine the argument received by the flatMap projection function with the observable's result: getData() .
Read more >Flux (reactor-core 3.5.0)
Build a Flux whose data are generated by the combination of the most recently published value from each of the Publisher sources provided...
Read more >Flowable (RxJava Javadoc 3.1.5) - ReactiveX
The Flowable class that implements the Reactive Streams Publisher Pattern and offers factory methods, intermediate operators and the ability to consume ...
Read more >X++ composite data types - Dynamics 365 - Microsoft Learn
A container is useful when you must pass various types of values between the client and server tiers. However, if you plan to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Try this:
@amanshuraikwar There is a library that may be what you are looking for: https://github.com/pakoito/Komprehensions