Lau*_*Lau 7 android reactive-programming rx-android
我想分开我的可观察的if/else声明
就像是:
A[] array = new A[10];
for (int i = 0; i < array.length; i++) {
array[i] = new A(getRandomString(), getRandomInt());
}
Observable.from(array)
.filter(a -> condition(a))
.// <--- do stuff if condition returns true
.// <- back to parent
.filter(a -> complexCondition(a)) // filter all elements(!)
.// <--- do stuff if complex condition returns true
.// <- back to iterate all elements
Run Code Online (Sandbox Code Playgroud)
它甚至可能吗?
在 Observable 中并不是这样工作的,你必须认为 observable 就像一个流,你最终可以得到一些项目,或者其他项目。您在可观察量中发现的最接近的 if/else 将使用 GroupsBy。
这里有一些我解释如何工作的实际例子
| 归档时间: |
|
| 查看次数: |
2239 次 |
| 最近记录: |