1 import rx : SubjectObject, CounterObserver;
2
3 auto hello = new SubjectObject!string;
4 auto world = new SubjectObject!string;
5
6 auto message = combineLatest!((a, b) => a ~ ", " ~ b ~ "!")(hello, world);
7
8 auto observer = new CounterObserver!string;
9 message.doSubscribe(observer);
10
11 .put(hello, "Hello");
12 .put(world, "world");
13
14 assert(observer.putCount == 1);
15 assert(observer.lastValue == "Hello, world!");
16
17 .put(world, "D-man");
18 assert(observer.putCount == 2);
19 assert(observer.lastValue == "Hello, D-man!");
1 import rx : SubjectObject, CounterObserver, uniq;
2
3 auto count1 = new SubjectObject!int;
4 auto count2 = new SubjectObject!int;
5 auto count3 = new SubjectObject!int;
6
7 import std.algorithm : max;
8
9 alias pickMax = combineLatest!max;
10 auto observable = pickMax(count1, count2, count3).uniq();
11
12 auto observer = new CounterObserver!int;
13 observable.doSubscribe(observer);
14
15 .put(count1, 0);
16 .put(count2, 0);
17 .put(count3, 0);
18
19 assert(observer.putCount == 1);
20 assert(observer.lastValue == 0);
21
22 .put(count1, 10);
23 assert(observer.putCount == 2);
24 assert(observer.lastValue == 10);
25
26 .put(count2, 10);
27 assert(observer.putCount == 2);
28
29 .put(count3, 11);
30 assert(observer.putCount == 3);
31 assert(observer.lastValue == 11);