
de.adito.util.reactive.ObservableCollectors Maven / Gradle / Ivy
package de.adito.util.reactive;
import io.reactivex.rxjava3.core.Observable;
import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.function.*;
import java.util.stream.Collector;
/**
* @author w.glanzer, 04.12.2018
*/
public class ObservableCollectors
{
private ObservableCollectors()
{
}
/**
* Returns a collector which combines an Stream of Observables to one observable.
* It is combined via Observable.combineLatest()
*
* @return the Collector
*/
@NotNull
public static Collector, ?, Observable>> combineToList()
{
return _combine(pData -> {
List values = new ArrayList<>();
for (Object data : pData)
values.add((T) data);
return values;
});
}
/**
* Returns a collector which combines an Stream of Observables to one observable.
* It is combined via Observable.combineLatest()
*
* @return the Collector
*/
@NotNull
public static Collector>, ?, Observable>> combineOptionalsToList()
{
return _combine(pData -> {
List values = new ArrayList<>();
for (Object data : pData)
((Optional) data).ifPresent(values::add);
return values;
});
}
/**
* Returns a collector which combines an Stream of Observables to one observable.
* It is combined via Observable.combineLatest()
*
* @return the Collector
*/
@NotNull
public static Collector>, ?, Observable>> combineListToList()
{
return _combine(pData -> {
List values = new ArrayList<>();
for (Object data : pData)
values.addAll(((List) data));
return values;
});
}
/**
* Returns an Collector which combines Observables to one Observable with a value-List
*
* @param pFn Function, which combines the Input-Values to a List of output-Values
* @param INPUT-Value-Type
* @param OUTPUT-Value-Type
* @return the Collector, not null
*/
@NotNull
private static Collector, ?, Observable>> _combine(@NotNull Function
© 2015 - 2025 Weber Informatics LLC | Privacy Policy