Skip to content

Commit fe95cfc

Browse files
committed
another flatmap example
1 parent be28f10 commit fe95cfc

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/main/java/com/mycompany/rx/java/manipulation/transformation/FlatMapOperator.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
import rx.Observable;
1010
import rx.functions.Func0;
1111
import rx.functions.Func1;
12+
import rx.functions.Func2;
1213

1314
public class FlatMapOperator {
1415

15-
public static void main(String[] args) {
16-
16+
public static void taking3FunctionsTransformingEventsIntoObservables() {
1717
Observable<Integer> flatMapped = Observable
1818
.just(-1, 0, 1)
1919
.map(new Func1<Integer, Integer>() {
@@ -41,8 +41,34 @@ public Observable<? extends Integer> call() {
4141
}
4242
});
4343

44-
SubscriptionPrint.displaySubscription(flatMapped, "FlatMap");
44+
SubscriptionPrint.displaySubscription(flatMapped, "taking3FunctionsTransformingEventsIntoObservables");
45+
}
4546

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();
4672
}
4773

4874
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy