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

1 import std.array;
2 import rx.subject;
3 
4 auto pub = new SubjectObject!int;
5 auto sub = appender!(int[]);
6 
7 auto d = pub.take(2).subscribe(sub);
8 foreach (i; 0 .. 10)
9 {
10     pub.put(i);
11 }
12 
13 import std.algorithm;
14 
15 assert(equal(sub.data, [0, 1]));