take

Creates a sub-observable consisting of only up to the first n elements of the given source.

take
(
TObservable
)
(
auto ref TObservable observable
,
size_t n
)

Examples

import std.array;
import rx.subject;

auto pub = new SubjectObject!int;
auto sub = appender!(int[]);

auto d = pub.take(2).subscribe(sub);
foreach (i; 0 .. 10)
{
    pub.put(i);
}

import std.algorithm;

assert(equal(sub.data, [0, 1]));

Meta