[add] flatmap
1 parent 28859f8 commit 480078d9250b341f33613d7f9863ddd6ab5301b2
KeijuMatsumoto authored on 12 Nov 2017
Showing 3 changed files
View
4
app/src/main/java/org/ntlab/developrx/JavaMainActivity.java
findViewById(R.id.timer_btn).setOnClickListener(view -> rxProcess.timer());
findViewById(R.id.error_btn).setOnClickListener(view -> rxProcess.error());
findViewById(R.id.map_btn).setOnClickListener(view -> rxProcess.map());
findViewById(R.id.empty_btn).setOnClickListener(view -> rxProcess.empy());
findViewById(R.id.flatmap_btn).setOnClickListener(view -> rxProcess.flatmap());
findViewById(R.id.flatmap_1_btn).setOnClickListener(view -> rxProcess.flatmap1());
findViewById(R.id.flatmap_2_btn).setOnClickListener(view -> rxProcess.flatmap2());
}
}
View
11
app/src/main/java/org/ntlab/developrx/JavaRxProcess.java
 
/**
* 受け取ったデータをFlowable/Observableに変換し、そのFlowable/Obsevableが持つデータを通知する
*/
public void flatmap() {
public void flatmap1() {
Flowable<String> flowable = Flowable.just("A", "", "B", "", "C")
.flatMap(data -> {
if (data.isEmpty()) {
return Flowable.empty();
}
});
flowable.subscribe(new DebugSubscriber<>());
}
 
public void flatmap2() {
Flowable<String> flowable = Flowable.range(1, 3)
.flatMap(
data -> Flowable.interval(100L, TimeUnit.MILLISECONDS).take(3),
(sourceData, newData) -> "[" + sourceData + "] " + newData
);
flowable.subscribe(new DebugSubscriber<>());
}
}
View
app/src/main/res/layout/activity_main_java.xml