takeLast

Creates a observable that take only a last element of the given source.

takeLast
(
TObservable
)
(
auto ref TObservable observable
)

Examples

1 import rx.subject;
2 
3 auto sub = new SubjectObject!int;
4 
5 int putCount = 0;
6 int completedCount = 0;
7 struct TestObserver
8 {
9     void put(int n)
10     {
11         putCount++;
12     }
13 
14     void completed()
15     {
16         completedCount++;
17     }
18 }
19 
20 auto d = sub.takeLast.subscribe(TestObserver());
21 
22 assert(putCount == 0);
23 sub.put(1);
24 assert(putCount == 0);
25 sub.put(10);
26 assert(putCount == 0);
27 sub.completed();
28 assert(putCount == 1);
29 assert(completedCount == 1);
30 
31 sub.put(100);
32 assert(putCount == 1);
33 assert(completedCount == 1);