-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathFlatMapAndFiles.java
More file actions
44 lines (33 loc) · 944 Bytes
/
FlatMapAndFiles.java
File metadata and controls
44 lines (33 loc) · 944 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
35
36
37
38
39
40
41
42
43
44
package com.packtpub.reactive.chapter04;
import static com.packtpub.reactive.common.Helpers.subscribePrint;
import java.nio.file.Paths;
import rx.Observable;
import com.packtpub.reactive.common.CreateObservable;
import com.packtpub.reactive.common.Program;
/**
* Demonstration of using flatMap with an Observable created by directory stream,
* reading all the files from it, using Observables.
*
* @author meddle
*/
public class FlatMapAndFiles implements Program {
@Override
public String name() {
return "Working with files using flatMap";
}
@Override
public int chapter() {
return 4;
}
@Override
public void run() {
Observable<String> fsObs = CreateObservable.listFolder(
Paths.get("src", "main", "resources"),
"{lorem.txt,letters.txt}")
.flatMap(path -> CreateObservable.from(path));
subscribePrint(fsObs, "FS");
}
public static void main(String[] args) {
new FlatMapAndFiles().run();
}
}