I have a list coming back from a REST endpoint. I need to break this list down into categories (a category is an element in every entry in the list). Certain categories will be cached for faster retrieval later.
I did not know if I could make .map () entries and provide some filters () or some type of case-case to place category entries in the right bucket.
Is it wise to implement something like this sound using rxJava?
UPDATE: Non-working version
private Map<String, List<VideoMetadataInfoEntity>> buildCategories( Observable<List<VideoMetadataInfoEntity>> videoList ) {
Map<String, List<VideoMetadataInfoEntity>> categoryMap = new HashMap<>();
videoList
.flatMap( Observable::from )
.subscribe( videoMetadataInfoEntity -> mapCategory(videoMetadataInfoEntity, categoryMap ) );
Observable.just( categoryMap )
.doOnNext( saveCategoriesToCacheAction );
return categoryMap;
}
However, this fire is in order, and this is my understanding, the second observable does not send anything saveCategoriesToCacheAction, since it is not subscribed to the result of the first observable.
, . . , , , . , . , . , , , , .