-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRxJavaSample17.java
More file actions
34 lines (25 loc) · 986 Bytes
/
RxJavaSample17.java
File metadata and controls
34 lines (25 loc) · 986 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
30
31
32
33
34
import rx.Observable;
import java.util.Arrays;
import java.util.List;
public class RxJavaSample17 {
public static void main(String[] args) {
query("Hello, world!")
.flatMap(urls -> Observable.from(urls))
.flatMap(url -> getTitle(url))
.filter(title -> title != null)
.take(5)
.doOnNext(title -> saveTitle(title))
.subscribe(title -> System.out.println(title));
}
private static void saveTitle(String title) {
System.out.println("title save - " + 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");
}
}