-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMain.java
More file actions
87 lines (68 loc) · 2.47 KB
/
Main.java
File metadata and controls
87 lines (68 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import hu.akarnokd.rxjava2.math.MathObservable;
import io.reactivex.Observable;
import java.util.Arrays;
import java.util.List;
public class Main {
public static void main( String[] args ) {
average();
sum();
reduce();
count();
}
/**
* Emit the average of numbers emitted by an Observable and terminate.
*
**/
private static void average() {
System.out.println("average");
List<Integer> integerList = Arrays.asList(1, 3);
System.out.println(integerList);
Observable<Integer> integerObservable = Observable.fromIterable(integerList);
System.out.println("average =====================>");
MathObservable.averageFloat(integerObservable)
.subscribe(System.out::println);
System.out.println();
}
/**
* Emit the sum of numbers emitted by an Observable and terminate.
*
**/
private static void sum() {
System.out.println("sum");
List<Integer> integerList = Arrays.asList(1, 2, 3);
System.out.println(integerList);
Observable<Integer> integerObservable = Observable.fromIterable(integerList);
System.out.println("sum =====================>");
MathObservable.sumInt(integerObservable)
.subscribe(System.out::println);
System.out.println();
}
/**
* Apply a function to each item emitted by an Observable, sequentially, emit the
* final value and terminate.
**/
private static void reduce() {
System.out.println("reduce");
List<Integer> integerList = Arrays.asList(1, 2, 3);
System.out.println(integerList);
Observable<Integer> integerObservable = Observable.fromIterable(integerList);
System.out.println("reduce((x, y) => x * y) =====================>");
integerObservable.reduce((x, y) -> x * y)
.subscribe(System.out::println);
System.out.println();
}
/**
* Emit the count of items emitted by an Observable and terminate.
*
**/
private static void count() {
System.out.println("count");
List<Integer> integerList = Arrays.asList(4, 8);
System.out.println(integerList);
Observable<Integer> integerObservable = Observable.fromIterable(integerList);
System.out.println("count =====================>");
integerObservable.count()
.subscribe(System.out::println);
System.out.println();
}
}