filter

Implements the higher order filter function. The predicate is passed to std.functional.unaryFun, and can either accept a string, or any callable that can be executed via pred(element).

template filter(alias pred)
filter
(
TObservable
)
(
auto ref TObservable observable
)

Examples

1 import rx.subject : Subject, SubjectObject;
2 import std.array : appender;
3 
4 Subject!int sub = new SubjectObject!int;
5 auto filtered = sub.filter!(n => n % 2 == 0);
6 auto buffer = appender!(int[])();
7 auto disposable = filtered.subscribe(buffer);
8 scope (exit)
9     disposable.dispose();
10 
11 sub.put(0);
12 sub.put(1);
13 sub.put(2);
14 sub.put(3);
15 
16 import std.algorithm : equal;
17 
18 assert(equal(buffer.data, [0, 2][]));