0
votes

I have two observables each will return a list of objects. I would like to collect these list and then use the DiffUtil feature from Android to delete the non-existing items from the first list. Anyone have any ideas for this aside from firing another observable from the onComplete of the first observable? Or is this even possible?

Observable1 -> List1
Observable2 -> List2
DiffUtil(List1, List2)
   delete from List1 items that are non-existent in List2
2

2 Answers

1
votes

Just use zip operator:

list1Observable.zipWith(list2Observable,
                (list1, list2) -> {
                //DiffUtil list1 and list2 and return the filtered list
                }
        );
0
votes

For two list I would use merge operator

/**
 * Here we merge two list and we sort the list for every new item added into.
 * Shall return
 * <p>
 * [1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15]
 */
@Test
public void testMergeLists() {
    Observable.merge(Observable.from(Arrays.asList(2, 1, 13, 11, 5)), Observable.from(Arrays.asList(10, 4, 12, 3, 14, 15)))
            .collect(ArrayList<Integer>::new, ArrayList::add)
            .doOnNext(Collections::sort)
            .subscribe(System.out::println);

}

You can see more examples here https://github.com/politrons/reactive