1 import rx.subject : SubjectObject; 2 3 auto sub = new SubjectObject!int; 4 auto sum = sub.fold!"a+b"(0); 5 6 int result = 0; 7 auto disposable = sum.doSubscribe((int n) { result = n; }); 8 scope (exit) 9 disposable.dispose(); 10 11 foreach (i; 1 .. 11) 12 sub.put(i); 13 14 assert(result == 0); 15 sub.completed(); 16 assert(result == 55);