|
9 | 9 | import rx.Observable;
|
10 | 10 | import rx.functions.Func0;
|
11 | 11 | import rx.functions.Func1;
|
| 12 | +import rx.functions.Func2; |
12 | 13 |
|
13 | 14 | public class FlatMapOperator {
|
14 | 15 |
|
15 |
| - public static void main(String[] args) { |
16 |
| - |
| 16 | + public static void taking3FunctionsTransformingEventsIntoObservables() { |
17 | 17 | Observable<Integer> flatMapped = Observable
|
18 | 18 | .just(-1, 0, 1)
|
19 | 19 | .map(new Func1<Integer, Integer>() {
|
@@ -41,8 +41,34 @@ public Observable<? extends Integer> call() {
|
41 | 41 | }
|
42 | 42 | });
|
43 | 43 |
|
44 |
| - SubscriptionPrint.displaySubscription(flatMapped, "FlatMap"); |
| 44 | + SubscriptionPrint.displaySubscription(flatMapped, "taking3FunctionsTransformingEventsIntoObservables"); |
| 45 | + } |
45 | 46 |
|
| 47 | + public static void combineSourceWithTriggeredBySource() { |
| 48 | + Observable<Integer> flatMapped = Observable |
| 49 | + .just(5, 432) |
| 50 | + .flatMap(new Func1<Integer, Observable<Integer>>() { |
| 51 | + @Override |
| 52 | + public Observable<Integer> call(Integer integer) { |
| 53 | + return Observable.range(integer, 2); |
| 54 | + } |
| 55 | + }, |
| 56 | + new Func2<Integer, Integer, Integer>() { |
| 57 | + @Override |
| 58 | + public Integer call(Integer x, Integer y) { |
| 59 | + return x + y; |
| 60 | + } |
| 61 | + } |
| 62 | + ); |
| 63 | + |
| 64 | + SubscriptionPrint.displaySubscription(flatMapped, "combineSourceWithTriggeredBySource"); |
| 65 | + |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | + public static void main(String[] args) { |
| 70 | + taking3FunctionsTransformingEventsIntoObservables(); |
| 71 | + combineSourceWithTriggeredBySource(); |
46 | 72 | }
|
47 | 73 |
|
48 | 74 | }
|
0 commit comments