本文整理匯總了Java中io.reactivex.Observable.groupBy方法的典型用法代碼示例。如果您正苦於以下問題:Java Observable.groupBy方法的具體用法?Java Observable.groupBy怎麽用?Java Observable.groupBy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.reactivex.Observable
的用法示例。
在下文中一共展示了Observable.groupBy方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: shouldBeNecessaryToSubscribetoStreamAfterSplitting
import io.reactivex.Observable; //導入方法依賴的package包/類
@Test
public void shouldBeNecessaryToSubscribetoStreamAfterSplitting() {
final double[] averages = {0, 0};
Observable<Integer> numbers = Observable.just(22, 22, 99, 22, 101, 22);
Function<Integer, Integer> keySelector = integer -> integer % 2;
Observable<GroupedObservable<Integer, Integer>> split = numbers.groupBy(keySelector);
split.subscribe(
group -> {
Observable<Double> convertToDouble = group.map(integer -> (double) integer);
Function<Double, Double> insertIntoAveragesArray = aDouble -> averages[group.getKey()] = aDouble;
convertToDouble.reduce((t1, t2) -> t1+t2).map(insertIntoAveragesArray).subscribe();
}
);
assertThat(averages[0]).isEqualTo(0);
assertThat(averages[1]).isEqualTo(0);
}
示例2: main
import io.reactivex.Observable; //導入方法依賴的package包/類
public static void main(String[] args) {
Observable<String> source =
Observable.just("Alpha", "Beta", "Gamma", "Delta",
"Epsilon");
Observable<GroupedObservable<Integer, String>> byLengths =
source.groupBy(s -> s.length());
byLengths.flatMapSingle(grp ->
grp.reduce("", (x, y) -> x.equals("") ? y : x + ", " + y)
.map(s -> grp.getKey() + ": " + s)
).subscribe(System.out::println);
}
示例3: main
import io.reactivex.Observable; //導入方法依賴的package包/類
public static void main(String[] args) {
Observable<String> source =
Observable.just("Alpha", "Beta", "Gamma", "Delta", "Epsilon");
Observable<GroupedObservable<Integer, String>> byLengths =
source.groupBy(s -> s.length());
}
示例4: main
import io.reactivex.Observable; //導入方法依賴的package包/類
public static void main(String[] args) {
Observable<String> source =
Observable.just("Alpha", "Beta", "Gamma", "Delta",
"Epsilon");
Observable<GroupedObservable<Integer, String>> byLengths =
source.groupBy(s -> s.length());
byLengths.flatMapSingle(grp -> grp.toList())
.subscribe(System.out::println);
}