-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRxJavaSample16.java
More file actions
29 lines (21 loc) · 823 Bytes
/
RxJavaSample16.java
File metadata and controls
29 lines (21 loc) · 823 Bytes
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
import rx.Observable;
import java.util.Arrays;
import java.util.List;
public class RxJavaSample16 {
public static void main(String[] args) {
query("Hello, world!")
.flatMap(urls -> Observable.from(urls))
.flatMap(url -> getTitle(url))
.filter(title -> title != null)
.take(5)
.subscribe(title -> System.out.println(title));
}
// Returns a List of website URLs based on a text search
public static Observable<List<String>> query(String text) {
return Observable.just(Arrays.asList("www.naver.com", "www.google.com", "www.kakao.com"));
}
// Returns the title of a website, or null if 404
public static Observable<String> getTitle(String URL) {
return Observable.just("title");
}
}