forked from mitocode21/java8mito
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRxApp.java
More file actions
67 lines (54 loc) · 1.36 KB
/
Copy pathRxApp.java
File metadata and controls
67 lines (54 loc) · 1.36 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
package com.mitocode.rxjava;
import java.util.ArrayList;
import java.util.List;
import rx.Observable;
import rx.functions.Action1;
public class RxApp {
private List<Integer> lista1;
private List<Integer> lista2;
public RxApp() {
lista1 = new ArrayList<>();
lista2 = new ArrayList<>();
this.llenarListas();
}
public void llenarListas() {
for (int i = 0; i < 10000; i++) {
lista1.add(i);
lista2.add(i);
}
}
public void buscar() {
Observable<Integer> obs1 = Observable.from(lista1);
Observable<Integer> obs2 = Observable.from(lista2);
/*Observable.merge(obs1, obs2).subscribe(new Action1<Integer>(){
@Override
public void call(Integer numero) {
if(numero == 1){
System.out.println(numero);
}
}
});*/
Observable.merge(obs1, obs2).filter(x->x==1).subscribe(System.out::println);
Observable.merge(obs1, obs2).filter(x->x==1).subscribe(x -> {
if(x == 1){
System.out.println(x);
}
});
}
public static void main(String[] args) {
/*
* List<String> lista = new ArrayList<>(); lista.add("Mito");
* lista.add("Code"); lista.add("MitoCode");
*
* Observable<String> obs = Observable.from(lista); obs.subscribe(new
* Action1<String>(){
*
* @Override public void call(String elemento) {
* System.out.println(elemento); }
*
* });
*/
RxApp app = new RxApp();
app.buscar();
}
}