skipWhile.js
1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Subscriber } from '../Subscriber';
export function skipWhile(predicate) {
return (source) => source.lift(new SkipWhileOperator(predicate));
}
class SkipWhileOperator {
constructor(predicate) {
this.predicate = predicate;
}
call(subscriber, source) {
return source.subscribe(new SkipWhileSubscriber(subscriber, this.predicate));
}
}
class SkipWhileSubscriber extends Subscriber {
constructor(destination, predicate) {
super(destination);
this.predicate = predicate;
this.skipping = true;
this.index = 0;
}
_next(value) {
const destination = this.destination;
if (this.skipping) {
this.tryCallPredicate(value);
}
if (!this.skipping) {
destination.next(value);
}
}
tryCallPredicate(value) {
try {
const result = this.predicate(value, this.index++);
this.skipping = Boolean(result);
}
catch (err) {
this.destination.error(err);
}
}
}
//# sourceMappingURL=skipWhile.js.map