【发布时间】:2018-01-26 13:28:22
【问题描述】:
我有一个来自 N 个可观察值的合并 EventStream。从这个值我想要最小的一个。例如:
Var<Integer> a = Var.newSimpleVar(2);
Var<Integer> b = Var.newSimpleVar(3);
Var<Integer> c = Var.newSimpleVar(4);
...
EventStream<Integer> m = EventStreams.merge(a.values(), b.values(), c.values(), ...);
m = m.filter(integer -> integer > 1).accumulate((i1, i2) -> Math.min(i1, i2));
m.subscribe(integer -> System.out.println(integer));
a.setValue(0); // At this point the Input is filtered and not emitted also I dont want the last value "2" in the accumulation.
b.setValue(5);
c.setValue(3);
//Output is always "2".
我的问题是,在第一个过滤值之后,我还想要一个用于累积的新初始值。在这种情况下,例如“Integer.MAX_VALUE”。
因此,累积中的下一个比较不是:
"Math.min(2,5)" -> "Math.min(2,3)"
但是
"Math.min(MAX_VALUE,5)" -> "Math.min(5,3)"。
所以输出不应该是:
2、2、2、2、2
但是
a -> 2 : 输出最小值 2
b -> 3 : 输出最小值 2
c -> 4 : 输出最小值 2
a -> 0 :OK 条件(值
b -> 5 : 输出最小值 5
c -> 3 : 输出最小值 3
a -> 4 : 输出最小值 3
...
【问题讨论】: