forked from PacktPublishing/Learning-RxJava-Second-Edition
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh9_03.java
More file actions
22 lines (20 loc) · 866 Bytes
/
Copy pathCh9_03.java
File metadata and controls
22 lines (20 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import com.google.common.collect.ImmutableList;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.FlowableTransformer;
public class Ch9_03 {
public static void main(String[] args) {
Flowable.just("Alpha", "Beta", "Gamma", "Delta", "Epsilon")
.compose(toImmutableList())
.subscribe(System.out::println);
Flowable.range(1, 10)
.compose(toImmutableList())
.subscribe(System.out::println);
}
private static <T> FlowableTransformer<T, ImmutableList<T>> toImmutableList() {
return upstream ->
upstream.collect(ImmutableList::<T>builder,
ImmutableList.Builder::add)
.map(ImmutableList.Builder::build)
.toFlowable(); // must turn Single into Flowable
}
}