This repository was archived by the owner on Apr 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathskipwhile.js
54 lines (47 loc) · 2.12 KB
/
skipwhile.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var SkipWhileObservable = (function (__super__) {
inherits(SkipWhileObservable, __super__);
function SkipWhileObservable(source, fn) {
this.source = source;
this._fn = fn;
__super__.call(this);
}
SkipWhileObservable.prototype.subscribeCore = function (o) {
return this.source.subscribe(new SkipWhileObserver(o, this));
};
return SkipWhileObservable;
}(ObservableBase));
var SkipWhileObserver = (function (__super__) {
inherits(SkipWhileObserver, __super__);
function SkipWhileObserver(o, p) {
this._o = o;
this._p = p;
this._i = 0;
this._r = false;
__super__.call(this);
}
SkipWhileObserver.prototype.next = function (x) {
if (!this._r) {
var res = tryCatch(this._p._fn)(x, this._i++, this._p);
if (res === errorObj) { return this._o.onError(res.e); }
this._r = !res;
}
this._r && this._o.onNext(x);
};
SkipWhileObserver.prototype.error = function (e) { this._o.onError(e); };
SkipWhileObserver.prototype.completed = function () { this._o.onCompleted(); };
return SkipWhileObserver;
}(AbstractObserver));
/**
* Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements.
* The element's index is used in the logic of the predicate function.
*
* var res = source.skipWhile(function (value) { return value < 10; });
* var res = source.skipWhile(function (value, index) { return value < 10 || index < 10; });
* @param {Function} predicate A function to test each element for a condition; the second parameter of the function represents the index of the source element.
* @param {Any} [thisArg] Object to use as this when executing callback.
* @returns {Observable} An observable sequence that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate.
*/
observableProto.skipWhile = function (predicate, thisArg) {
var fn = bindCallback(predicate, thisArg, 3);
return new SkipWhileObservable(this, fn);
};