本文整理汇总了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);
}