map

template map(alias f)
MapObservable!(f, TObservable)
map
(
TObservable
)
(
auto ref TObservable observable
)

Examples

1 import rx.subject;
2 import std.array : appender;
3 import std.conv : to;
4 
5 Subject!int sub = new SubjectObject!int;
6 auto mapped = sub.map!(n => to!string(n));
7 static assert(isObservable!(typeof(mapped), string));
8 static assert(isSubscribable!(typeof(mapped), Observer!string));
9 
10 auto buffer = appender!(string[])();
11 auto disposable = mapped.subscribe(buffer);
12 scope (exit)
13     disposable.dispose();
14 
15 sub.put(0);
16 sub.put(1);
17 sub.put(2);
18 
19 import std.algorithm : equal;
20 
21 assert(equal(buffer.data, ["0", "1", "2"][]));
1 import rx.subject;
2 import std.array : appender;
3 import std.conv : to;
4 
5 Subject!int sub = new SubjectObject!int;
6 auto mapped = sub.map!"a * 2";
7 static assert(isObservable!(typeof(mapped), int));
8 static assert(isSubscribable!(typeof(mapped), Observer!int));
9 
10 auto buffer = appender!(int[])();
11 auto disposable = mapped.subscribe(buffer);
12 scope (exit)
13     disposable.dispose();
14 
15 sub.put(0);
16 sub.put(1);
17 sub.put(2);
18 
19 import std.algorithm : equal;
20 
21 assert(equal(buffer.data, [0, 2, 4][]));