RxJavaExtensions
RxJavaExtensions copied to clipboard
Union of multiple observables
Is there an operator or an easy way to generate a union of elements from different observables? Meaning that only elements that exists in all observales should be pushed downstream. Would be also great if there could be an option to define the comparator.
Meaning, I would expect:
A = [1, 2, 4, 5]
B = [2, 5, 7]
C = [0, 1, 2, 5, 7]
UNION (A, B, C) = [2, 5]
Maybe something like this exists in the RxJava itself?
No single operator but you can achieve it via combination of several:
- collect each source into a set
- zip these and in the handler, use set1.retainAll(set2); set1.retainAll(set3); return set1;
- use flatMapIterable to unroll the resulting intersection set.