distinctUntilChanged

  1. template uniq(alias pred = "a == b")
  2. alias distinctUntilChanged = uniq
    alias distinctUntilChanged = uniq

Examples

ditto

1 import rx.subject : SubjectObject;
2 import std.array : appender;
3 
4 auto sub = new SubjectObject!int;
5 auto buf = appender!(int[]);
6 
7 auto disposable = sub.uniq.subscribe(buf);
8 scope (exit)
9     disposable.dispose();
10 
11 .put(sub, [11, 11, 22, 22, 33]);
12 
13 auto data = buf.data;
14 assert(data.length == 3);
15 assert(data[0] == 11);
16 assert(data[1] == 22);
17 assert(data[2] == 33);

ditto

1 import std.datetime : Date;
2 import rx.subject : SubjectObject;
3 import std.array : appender;
4 
5 auto sub = new SubjectObject!Date;
6 auto buf = appender!(Date[]);
7 
8 auto disposable = sub.uniq!"a.year == b.year".subscribe(buf);
9 scope (exit)
10     disposable.dispose();
11 
12 .put(sub, Date(2000, 1, 1));
13 .put(sub, Date(2000, 1, 2));
14 .put(sub, Date(2017, 3, 24));
15 .put(sub, Date(2017, 4, 24));
16 .put(sub, Date(2017, 4, 24));
17 
18 auto data = buf.data;
19 assert(data.length == 2);
20 assert(data[0] == Date(2000, 1, 1));
21 assert(data[1] == Date(2017, 3, 24));

ditto

1 import std.datetime : Date;
2 import rx.subject : SubjectObject;
3 import std.array : appender;
4 
5 auto sub = new SubjectObject!Date;
6 auto buf = appender!(Date[]);
7 
8 auto disposable = sub.distinctUntilChanged!"a.year == b.year".subscribe(buf);
9 scope (exit)
10     disposable.dispose();
11 
12 .put(sub, Date(2000, 1, 1));
13 .put(sub, Date(2000, 1, 2));
14 .put(sub, Date(2017, 3, 24));
15 .put(sub, Date(2017, 4, 24));
16 .put(sub, Date(2017, 4, 24));
17 
18 auto data = buf.data;
19 assert(data.length == 2);
20 assert(data[0] == Date(2000, 1, 1));
21 assert(data[1] == Date(2017, 3, 24));