map

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

Members

Functions

map
MapObservable!(f, TObservable) map(TObservable observable)
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

import rx.subject;
import std.array : appender;
import std.conv : to;

Subject!int sub = new SubjectObject!int;
auto mapped = sub.map!(n => to!string(n));
static assert(isObservable!(typeof(mapped), string));
static assert(isSubscribable!(typeof(mapped), Observer!string));

auto buffer = appender!(string[])();
auto disposable = mapped.subscribe(buffer);
scope (exit)
    disposable.dispose();

sub.put(0);
sub.put(1);
sub.put(2);

import std.algorithm : equal;

assert(equal(buffer.data, ["0", "1", "2"][]));
import rx.subject;
import std.array : appender;
import std.conv : to;

Subject!int sub = new SubjectObject!int;
auto mapped = sub.map!"a * 2";
static assert(isObservable!(typeof(mapped), int));
static assert(isSubscribable!(typeof(mapped), Observer!int));

auto buffer = appender!(int[])();
auto disposable = mapped.subscribe(buffer);
scope (exit)
    disposable.dispose();

sub.put(0);
sub.put(1);
sub.put(2);

import std.algorithm : equal;

assert(equal(buffer.data, [0, 2, 4][]));

Meta