The high level problem I'm trying to solve is transforming a list of Foo objects contained in a fetched FooContainer (Observable) to a list of FooBar objects using RxJava.
My (confused) attempt:
fooContainerObservable
.map(container -> container.getFooList())
.flatMap(foo -> transformFooToFooBar(foo))
.collect( /* What do I do here? Is collect the correct thing? Should I be using lift? */)
.subscribe(fooBarList -> /* Display the list */);
My confusion (or at least one point of it) is the step moving the flattened list back to a list.
Note: I'm attempting to do this in an Android app.
toList can collect all items of an Observable into a List and emit it. toList can be implemented using collect, but it's much easier than collect. For your example, it will be:
fooContainerObservable
.map(container -> container.getFooList())
.flatMap(foo -> transformFooToFooBar(foo))
.toList()
.subscribe(fooBarList -> /* Display the list */);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With