rxjs-rails 2.3.14 → 2.3.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rxjs/rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/rx.aggregates.js +325 -370
  4. data/vendor/assets/javascripts/rx.aggregates.min.js +1 -1
  5. data/vendor/assets/javascripts/rx.all.compat.js +1115 -930
  6. data/vendor/assets/javascripts/rx.all.compat.min.js +4 -3
  7. data/vendor/assets/javascripts/rx.all.js +1113 -928
  8. data/vendor/assets/javascripts/rx.all.min.js +3 -3
  9. data/vendor/assets/javascripts/rx.async.compat.js +16 -20
  10. data/vendor/assets/javascripts/rx.async.compat.min.js +1 -1
  11. data/vendor/assets/javascripts/rx.async.js +14 -18
  12. data/vendor/assets/javascripts/rx.async.min.js +1 -1
  13. data/vendor/assets/javascripts/rx.backpressure.js +26 -10
  14. data/vendor/assets/javascripts/rx.backpressure.min.js +1 -1
  15. data/vendor/assets/javascripts/rx.binding.js +2 -14
  16. data/vendor/assets/javascripts/rx.binding.min.js +1 -1
  17. data/vendor/assets/javascripts/rx.coincidence.js +13 -13
  18. data/vendor/assets/javascripts/rx.coincidence.min.js +1 -1
  19. data/vendor/assets/javascripts/rx.compat.js +586 -378
  20. data/vendor/assets/javascripts/rx.compat.min.js +2 -2
  21. data/vendor/assets/javascripts/rx.experimental.js +37 -29
  22. data/vendor/assets/javascripts/rx.experimental.min.js +1 -1
  23. data/vendor/assets/javascripts/rx.js +586 -378
  24. data/vendor/assets/javascripts/rx.lite.compat.js +632 -394
  25. data/vendor/assets/javascripts/rx.lite.compat.min.js +2 -2
  26. data/vendor/assets/javascripts/rx.lite.extras.js +29 -25
  27. data/vendor/assets/javascripts/rx.lite.extras.min.js +1 -1
  28. data/vendor/assets/javascripts/rx.lite.js +630 -392
  29. data/vendor/assets/javascripts/rx.lite.min.js +2 -2
  30. data/vendor/assets/javascripts/rx.min.js +2 -2
  31. data/vendor/assets/javascripts/rx.sorting.js +72 -0
  32. data/vendor/assets/javascripts/rx.sorting.min.js +3 -0
  33. data/vendor/assets/javascripts/rx.testing.js +116 -83
  34. data/vendor/assets/javascripts/rx.testing.min.js +1 -1
  35. data/vendor/assets/javascripts/rx.time.js +127 -101
  36. data/vendor/assets/javascripts/rx.time.min.js +1 -1
  37. metadata +4 -2
@@ -24,7 +24,7 @@
24
24
  var Rx = {
25
25
  internals: {},
26
26
  config: {
27
- Promise: root.Promise // Detect if promise exists
27
+ Promise: root.Promise,
28
28
  },
29
29
  helpers: { }
30
30
  };
@@ -66,6 +66,104 @@
66
66
  var objectDisposed = 'Object has been disposed';
67
67
  function checkDisposed() { if (this.isDisposed) { throw new Error(objectDisposed); } }
68
68
 
69
+ Rx.config.longStackSupport = false;
70
+ var hasStacks = false;
71
+ try {
72
+ throw new Error();
73
+ } catch (e) {
74
+ hasStacks = !!e.stack;
75
+ }
76
+
77
+ // All code after this point will be filtered from stack traces reported by RxJS
78
+ var rStartingLine = captureLine(), rFileName;
79
+
80
+ var STACK_JUMP_SEPARATOR = "From previous event:";
81
+
82
+ function makeStackTraceLong(error, observable) {
83
+ // If possible, transform the error stack trace by removing Node and RxJS
84
+ // cruft, then concatenating with the stack trace of `observable`.
85
+ if (hasStacks &&
86
+ observable.stack &&
87
+ typeof error === "object" &&
88
+ error !== null &&
89
+ error.stack &&
90
+ error.stack.indexOf(STACK_JUMP_SEPARATOR) === -1
91
+ ) {
92
+ var stacks = [];
93
+ for (var o = observable; !!o; o = o.source) {
94
+ if (o.stack) {
95
+ stacks.unshift(o.stack);
96
+ }
97
+ }
98
+ stacks.unshift(error.stack);
99
+
100
+ var concatedStacks = stacks.join("\n" + STACK_JUMP_SEPARATOR + "\n");
101
+ error.stack = filterStackString(concatedStacks);
102
+ }
103
+ }
104
+
105
+ function filterStackString(stackString) {
106
+ var lines = stackString.split("\n"),
107
+ desiredLines = [];
108
+ for (var i = 0, len = lines.length; i < len; i++) {
109
+ var line = lines[i];
110
+
111
+ if (!isInternalFrame(line) && !isNodeFrame(line) && line) {
112
+ desiredLines.push(line);
113
+ }
114
+ }
115
+ return desiredLines.join("\n");
116
+ }
117
+
118
+ function isInternalFrame(stackLine) {
119
+ var fileNameAndLineNumber = getFileNameAndLineNumber(stackLine);
120
+ if (!fileNameAndLineNumber) {
121
+ return false;
122
+ }
123
+ var fileName = fileNameAndLineNumber[0], lineNumber = fileNameAndLineNumber[1];
124
+
125
+ console.log(rFileName, rStartingLine, rEndingLine);
126
+
127
+ return fileName === rFileName &&
128
+ lineNumber >= rStartingLine &&
129
+ lineNumber <= rEndingLine;
130
+ }
131
+
132
+ function isNodeFrame(stackLine) {
133
+ return stackLine.indexOf("(module.js:") !== -1 ||
134
+ stackLine.indexOf("(node.js:") !== -1;
135
+ }
136
+
137
+ function captureLine() {
138
+ if (!hasStacks) { return; }
139
+
140
+ try {
141
+ throw new Error();
142
+ } catch (e) {
143
+ var lines = e.stack.split("\n");
144
+ var firstLine = lines[0].indexOf("@") > 0 ? lines[1] : lines[2];
145
+ var fileNameAndLineNumber = getFileNameAndLineNumber(firstLine);
146
+ if (!fileNameAndLineNumber) { return; }
147
+
148
+ rFileName = fileNameAndLineNumber[0];
149
+ return fileNameAndLineNumber[1];
150
+ }
151
+ }
152
+
153
+ function getFileNameAndLineNumber(stackLine) {
154
+ // Named functions: "at functionName (filename:lineNumber:columnNumber)"
155
+ var attempt1 = /at .+ \((.+):(\d+):(?:\d+)\)$/.exec(stackLine);
156
+ if (attempt1) { return [attempt1[1], Number(attempt1[2])]; }
157
+
158
+ // Anonymous functions: "at filename:lineNumber:columnNumber"
159
+ var attempt2 = /at ([^ ]+):(\d+):(?:\d+)$/.exec(stackLine);
160
+ if (attempt2) { return [attempt2[1], Number(attempt2[2])]; }
161
+
162
+ // Firefox style: "function@filename:lineNumber or @filename:lineNumber"
163
+ var attempt3 = /.*@(.+):(\d+)$/.exec(stackLine);
164
+ if (attempt3) { return [attempt3[1], Number(attempt3[2])]; }
165
+ }
166
+
69
167
  // Shim in iterator support
70
168
  var $iterator$ = (typeof Symbol === 'function' && Symbol.iterator) ||
71
169
  '_es6shim_iterator_';
@@ -76,7 +174,21 @@
76
174
 
77
175
  var doneEnumerator = Rx.doneEnumerator = { done: true, value: undefined };
78
176
 
79
- Rx.iterator = $iterator$;
177
+ var isIterable = Rx.helpers.isIterable = function (o) {
178
+ return o[$iterator$] !== undefined;
179
+ }
180
+
181
+ var isArrayLike = Rx.helpers.isArrayLike = function (o) {
182
+ return o && o.length !== undefined;
183
+ }
184
+
185
+ Rx.helpers.iterator = $iterator$;
186
+
187
+ var deprecate = Rx.helpers.deprecate = function (name, alternative) {
188
+ /*if (typeof console !== "undefined" && typeof console.warn === "function") {
189
+ console.warn(name + ' is deprecated, use ' + alternative + ' instead.', new Error('').stack);
190
+ }*/
191
+ }
80
192
 
81
193
  /** `Object#toString` result shortcuts */
82
194
  var argsClass = '[object Arguments]',
@@ -93,15 +205,16 @@
93
205
  var toString = Object.prototype.toString,
94
206
  hasOwnProperty = Object.prototype.hasOwnProperty,
95
207
  supportsArgsClass = toString.call(arguments) == argsClass, // For less <IE9 && FF<4
96
- suportNodeClass,
208
+ supportNodeClass,
97
209
  errorProto = Error.prototype,
98
210
  objectProto = Object.prototype,
211
+ stringProto = String.prototype,
99
212
  propertyIsEnumerable = objectProto.propertyIsEnumerable;
100
213
 
101
214
  try {
102
- suportNodeClass = !(toString.call(document) == objectClass && !({ 'toString': 0 } + ''));
103
- } catch(e) {
104
- suportNodeClass = true;
215
+ supportNodeClass = !(toString.call(document) == objectClass && !({ 'toString': 0 } + ''));
216
+ } catch (e) {
217
+ supportNodeClass = true;
105
218
  }
106
219
 
107
220
  var shadowedProps = [
@@ -206,7 +319,7 @@
206
319
  return typeof value.toString != 'function' && typeof (value + '') == 'string';
207
320
  }
208
321
 
209
- function isArguments(value) {
322
+ var isArguments = function(value) {
210
323
  return (value && typeof value == 'object') ? toString.call(value) == argsClass : false;
211
324
  }
212
325
 
@@ -262,10 +375,10 @@
262
375
 
263
376
  case numberClass:
264
377
  // treat `NaN` vs. `NaN` as equal
265
- return (a != +a)
266
- ? b != +b
378
+ return (a != +a) ?
379
+ b != +b :
267
380
  // but treat `-0` vs. `+0` as not equal
268
- : (a == 0 ? (1 / a == 1 / b) : a == +b);
381
+ (a == 0 ? (1 / a == 1 / b) : a == +b);
269
382
 
270
383
  case regexpClass:
271
384
  case stringClass:
@@ -1175,15 +1288,13 @@ if (!Array.prototype.forEach) {
1175
1288
  return SchedulePeriodicRecursive;
1176
1289
  }());
1177
1290
 
1178
- /**
1179
- * Gets a scheduler that schedules work immediately on the current thread.
1180
- */
1291
+ /** Gets a scheduler that schedules work immediately on the current thread. */
1181
1292
  var immediateScheduler = Scheduler.immediate = (function () {
1182
1293
 
1183
1294
  function scheduleNow(state, action) { return action(this, state); }
1184
1295
 
1185
1296
  function scheduleRelative(state, dueTime, action) {
1186
- var dt = normalizeTime(dt);
1297
+ var dt = normalizeTime(dueTime);
1187
1298
  while (dt - this.now() > 0) { }
1188
1299
  return action(this, state);
1189
1300
  }
@@ -1297,24 +1408,24 @@ if (!Array.prototype.forEach) {
1297
1408
  oldHandler = root.onmessage;
1298
1409
  // Test for async
1299
1410
  root.onmessage = function () { isAsync = true; };
1300
- root.postMessage('','*');
1411
+ root.postMessage('', '*');
1301
1412
  root.onmessage = oldHandler;
1302
1413
 
1303
1414
  return isAsync;
1304
1415
  }
1305
1416
 
1306
- // Use in order, nextTick, setImmediate, postMessage, MessageChannel, script readystatechanged, setTimeout
1307
- if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1308
- scheduleMethod = process.nextTick;
1309
- } else if (typeof setImmediate === 'function') {
1417
+ // Use in order, setImmediate, nextTick, postMessage, MessageChannel, script readystatechanged, setTimeout
1418
+ if (typeof setImmediate === 'function') {
1310
1419
  scheduleMethod = setImmediate;
1311
1420
  clearMethod = clearImmediate;
1421
+ } else if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
1422
+ scheduleMethod = process.nextTick;
1312
1423
  } else if (postMessageSupported()) {
1313
1424
  var MSG_PREFIX = 'ms.rx.schedule' + Math.random(),
1314
1425
  tasks = {},
1315
1426
  taskId = 0;
1316
1427
 
1317
- function onGlobalPostMessage(event) {
1428
+ var onGlobalPostMessage = function (event) {
1318
1429
  // Only if we're a match to avoid any other global events
1319
1430
  if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
1320
1431
  var handleId = event.data.substring(MSG_PREFIX.length),
@@ -1615,8 +1726,8 @@ if (!Array.prototype.forEach) {
1615
1726
  var e;
1616
1727
  try {
1617
1728
  e = sources[$iterator$]();
1618
- } catch(err) {
1619
- observer.onError();
1729
+ } catch (err) {
1730
+ observer.onError(err);
1620
1731
  return;
1621
1732
  }
1622
1733
 
@@ -1657,14 +1768,14 @@ if (!Array.prototype.forEach) {
1657
1768
  });
1658
1769
  };
1659
1770
 
1660
- Enumerable.prototype.catchException = function () {
1771
+ Enumerable.prototype.catchError = function () {
1661
1772
  var sources = this;
1662
1773
  return new AnonymousObservable(function (observer) {
1663
1774
  var e;
1664
1775
  try {
1665
1776
  e = sources[$iterator$]();
1666
- } catch(err) {
1667
- observer.onError();
1777
+ } catch (err) {
1778
+ observer.onError(err);
1668
1779
  return;
1669
1780
  }
1670
1781
 
@@ -1802,7 +1913,7 @@ if (!Array.prototype.forEach) {
1802
1913
  * @param {Scheduler} scheduler Scheduler to schedule observer messages on.
1803
1914
  * @returns {Observer} Observer whose messages are scheduled on the given scheduler.
1804
1915
  */
1805
- Observer.notifyOn = function (scheduler) {
1916
+ Observer.prototype.notifyOn = function (scheduler) {
1806
1917
  return new ObserveOnObserver(scheduler, this);
1807
1918
  };
1808
1919
 
@@ -1983,23 +2094,17 @@ if (!Array.prototype.forEach) {
1983
2094
 
1984
2095
  ScheduledObserver.prototype.next = function (value) {
1985
2096
  var self = this;
1986
- this.queue.push(function () {
1987
- self.observer.onNext(value);
1988
- });
2097
+ this.queue.push(function () { self.observer.onNext(value); });
1989
2098
  };
1990
2099
 
1991
- ScheduledObserver.prototype.error = function (err) {
2100
+ ScheduledObserver.prototype.error = function (e) {
1992
2101
  var self = this;
1993
- this.queue.push(function () {
1994
- self.observer.onError(err);
1995
- });
2102
+ this.queue.push(function () { self.observer.onError(e); });
1996
2103
  };
1997
2104
 
1998
2105
  ScheduledObserver.prototype.completed = function () {
1999
2106
  var self = this;
2000
- this.queue.push(function () {
2001
- self.observer.onCompleted();
2002
- });
2107
+ this.queue.push(function () { self.observer.onCompleted(); });
2003
2108
  };
2004
2109
 
2005
2110
  ScheduledObserver.prototype.ensureActive = function () {
@@ -2040,8 +2145,9 @@ if (!Array.prototype.forEach) {
2040
2145
  var ObserveOnObserver = (function (__super__) {
2041
2146
  inherits(ObserveOnObserver, __super__);
2042
2147
 
2043
- function ObserveOnObserver() {
2044
- __super__.apply(this, arguments);
2148
+ function ObserveOnObserver(scheduler, observer, cancel) {
2149
+ __super__.call(this, scheduler, observer);
2150
+ this._cancel = cancel;
2045
2151
  }
2046
2152
 
2047
2153
  ObserveOnObserver.prototype.next = function (value) {
@@ -2059,6 +2165,12 @@ if (!Array.prototype.forEach) {
2059
2165
  this.ensureActive();
2060
2166
  };
2061
2167
 
2168
+ ObserveOnObserver.prototype.dispose = function () {
2169
+ __super__.prototype.dispose.call(this);
2170
+ this._cancel && this._cancel.dispose();
2171
+ this._cancel = null;
2172
+ };
2173
+
2062
2174
  return ObserveOnObserver;
2063
2175
  })(ScheduledObserver);
2064
2176
 
@@ -2070,6 +2182,24 @@ if (!Array.prototype.forEach) {
2070
2182
  var Observable = Rx.Observable = (function () {
2071
2183
 
2072
2184
  function Observable(subscribe) {
2185
+ if (Rx.config.longStackSupport && hasStacks) {
2186
+ try {
2187
+ throw new Error();
2188
+ } catch (e) {
2189
+ this.stack = e.stack.substring(e.stack.indexOf("\n") + 1);
2190
+ }
2191
+
2192
+ var self = this;
2193
+ this._subscribe = function (observer) {
2194
+ observer.onError = function (err) {
2195
+ makeStackTraceLong(self, err);
2196
+ observer.onError(err);
2197
+ };
2198
+
2199
+ subscribe(observer);
2200
+ };
2201
+ }
2202
+
2073
2203
  this._subscribe = subscribe;
2074
2204
  }
2075
2205
 
@@ -2134,7 +2264,7 @@ if (!Array.prototype.forEach) {
2134
2264
  var source = this;
2135
2265
  return new AnonymousObservable(function (observer) {
2136
2266
  return source.subscribe(new ObserveOnObserver(scheduler, observer));
2137
- });
2267
+ }, source);
2138
2268
  };
2139
2269
 
2140
2270
  /**
@@ -2156,7 +2286,7 @@ if (!Array.prototype.forEach) {
2156
2286
  d.setDisposable(new ScheduledDisposable(scheduler, source.subscribe(observer)));
2157
2287
  }));
2158
2288
  return d;
2159
- });
2289
+ }, source);
2160
2290
  };
2161
2291
 
2162
2292
  /**
@@ -2170,10 +2300,8 @@ if (!Array.prototype.forEach) {
2170
2300
 
2171
2301
  promise.then(
2172
2302
  function (value) {
2173
- if (!subject.isDisposed) {
2174
- subject.onNext(value);
2175
- subject.onCompleted();
2176
- }
2303
+ subject.onNext(value);
2304
+ subject.onCompleted();
2177
2305
  },
2178
2306
  subject.onError.bind(subject));
2179
2307
 
@@ -2209,36 +2337,34 @@ if (!Array.prototype.forEach) {
2209
2337
  };
2210
2338
 
2211
2339
  /**
2212
- * Creates a list from an observable sequence.
2213
- * @returns An observable sequence containing a single element with a list containing all the elements of the source sequence.
2340
+ * Creates an array from an observable sequence.
2341
+ * @returns {Observable} An observable sequence containing a single element with a list containing all the elements of the source sequence.
2214
2342
  */
2215
2343
  observableProto.toArray = function () {
2216
- var self = this;
2344
+ var source = this;
2217
2345
  return new AnonymousObservable(function(observer) {
2218
2346
  var arr = [];
2219
- return self.subscribe(
2347
+ return source.subscribe(
2220
2348
  arr.push.bind(arr),
2221
2349
  observer.onError.bind(observer),
2222
2350
  function () {
2223
2351
  observer.onNext(arr);
2224
2352
  observer.onCompleted();
2225
2353
  });
2226
- });
2354
+ }, source);
2227
2355
  };
2228
2356
 
2229
2357
  /**
2230
2358
  * Creates an observable sequence from a specified subscribe method implementation.
2231
- *
2232
2359
  * @example
2233
2360
  * var res = Rx.Observable.create(function (observer) { return function () { } );
2234
2361
  * var res = Rx.Observable.create(function (observer) { return Rx.Disposable.empty; } );
2235
2362
  * var res = Rx.Observable.create(function (observer) { } );
2236
- *
2237
2363
  * @param {Function} subscribe Implementation of the resulting observable sequence's subscribe method, returning a function that will be wrapped in a Disposable.
2238
2364
  * @returns {Observable} The observable sequence with the specified implementation for the Subscribe method.
2239
2365
  */
2240
- Observable.create = Observable.createWithDisposable = function (subscribe) {
2241
- return new AnonymousObservable(subscribe);
2366
+ Observable.create = Observable.createWithDisposable = function (subscribe, parent) {
2367
+ return new AnonymousObservable(subscribe, parent);
2242
2368
  };
2243
2369
 
2244
2370
  /**
@@ -2282,6 +2408,60 @@ if (!Array.prototype.forEach) {
2282
2408
 
2283
2409
  var maxSafeInteger = Math.pow(2, 53) - 1;
2284
2410
 
2411
+ function StringIterable(str) {
2412
+ this._s = s;
2413
+ }
2414
+
2415
+ StringIterable.prototype[$iterator$] = function () {
2416
+ return new StringIterator(this._s);
2417
+ };
2418
+
2419
+ function StringIterator(str) {
2420
+ this._s = s;
2421
+ this._l = s.length;
2422
+ this._i = 0;
2423
+ }
2424
+
2425
+ StringIterator.prototype[$iterator$] = function () {
2426
+ return this;
2427
+ };
2428
+
2429
+ StringIterator.prototype.next = function () {
2430
+ if (this._i < this._l) {
2431
+ var val = this._s.charAt(this._i++);
2432
+ return { done: false, value: val };
2433
+ } else {
2434
+ return doneEnumerator;
2435
+ }
2436
+ };
2437
+
2438
+ function ArrayIterable(a) {
2439
+ this._a = a;
2440
+ }
2441
+
2442
+ ArrayIterable.prototype[$iterator$] = function () {
2443
+ return new ArrayIterator(this._a);
2444
+ };
2445
+
2446
+ function ArrayIterator(a) {
2447
+ this._a = a;
2448
+ this._l = toLength(a);
2449
+ this._i = 0;
2450
+ }
2451
+
2452
+ ArrayIterator.prototype[$iterator$] = function () {
2453
+ return this;
2454
+ };
2455
+
2456
+ ArrayIterator.prototype.next = function () {
2457
+ if (this._i < this._l) {
2458
+ var val = this._a[this._i++];
2459
+ return { done: false, value: val };
2460
+ } else {
2461
+ return doneEnumerator;
2462
+ }
2463
+ };
2464
+
2285
2465
  function numberIsFinite(value) {
2286
2466
  return typeof value === 'number' && root.isFinite(value);
2287
2467
  }
@@ -2290,8 +2470,18 @@ if (!Array.prototype.forEach) {
2290
2470
  return n !== n;
2291
2471
  }
2292
2472
 
2293
- function isIterable(o) {
2294
- return o[$iterator$] !== undefined;
2473
+ function getIterable(o) {
2474
+ var i = o[$iterator$], it;
2475
+ if (!i && typeof o === 'string') {
2476
+ it = new StringIterable(o);
2477
+ return it[$iterator$]();
2478
+ }
2479
+ if (!i && o.length !== undefined) {
2480
+ it = new ArrayIterable(o);
2481
+ return it[$iterator$]();
2482
+ }
2483
+ if (!i) { throw new TypeError('Object is not iterable'); }
2484
+ return o[$iterator$]();
2295
2485
  }
2296
2486
 
2297
2487
  function sign(value) {
@@ -2311,10 +2501,6 @@ if (!Array.prototype.forEach) {
2311
2501
  return len;
2312
2502
  }
2313
2503
 
2314
- function isCallable(f) {
2315
- return Object.prototype.toString.call(f) === '[object Function]' && typeof f === 'function';
2316
- }
2317
-
2318
2504
  /**
2319
2505
  * This method creates a new Observable sequence from an array-like or iterable object.
2320
2506
  * @param {Any} arrayLike An array-like or iterable object to convert to an Observable sequence.
@@ -2326,66 +2512,52 @@ if (!Array.prototype.forEach) {
2326
2512
  if (iterable == null) {
2327
2513
  throw new Error('iterable cannot be null.')
2328
2514
  }
2329
- if (mapFn && !isCallable(mapFn)) {
2515
+ if (mapFn && !isFunction(mapFn)) {
2330
2516
  throw new Error('mapFn when provided must be a function');
2331
2517
  }
2332
2518
  isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2519
+ var list = Object(iterable), it = getIterable(list);
2333
2520
  return new AnonymousObservable(function (observer) {
2334
- var list = Object(iterable),
2335
- objIsIterable = isIterable(list),
2336
- len = objIsIterable ? 0 : toLength(list),
2337
- it = objIsIterable ? list[$iterator$]() : null,
2338
- i = 0;
2521
+ var i = 0;
2339
2522
  return scheduler.scheduleRecursive(function (self) {
2340
- if (i < len || objIsIterable) {
2341
- var result;
2342
- if (objIsIterable) {
2343
- var next;
2344
- try {
2345
- next = it.next();
2346
- } catch (e) {
2347
- observer.onError(e);
2348
- return;
2349
- }
2350
- if (next.done) {
2351
- observer.onCompleted();
2352
- return;
2353
- }
2523
+ var next;
2524
+ try {
2525
+ next = it.next();
2526
+ } catch (e) {
2527
+ observer.onError(e);
2528
+ return;
2529
+ }
2530
+ if (next.done) {
2531
+ observer.onCompleted();
2532
+ return;
2533
+ }
2354
2534
 
2355
- result = next.value;
2356
- } else {
2357
- result = !!list.charAt ? list.charAt(i) : list[i];
2358
- }
2535
+ var result = next.value;
2359
2536
 
2360
- if (mapFn && isCallable(mapFn)) {
2361
- try {
2362
- result = thisArg ? mapFn.call(thisArg, result, i) : mapFn(result, i);
2363
- } catch (e) {
2364
- observer.onError(e);
2365
- return;
2366
- }
2537
+ if (mapFn && isFunction(mapFn)) {
2538
+ try {
2539
+ result = mapFn.call(thisArg, result, i);
2540
+ } catch (e) {
2541
+ observer.onError(e);
2542
+ return;
2367
2543
  }
2368
-
2369
- observer.onNext(result);
2370
- i++;
2371
- self();
2372
- } else {
2373
- observer.onCompleted();
2374
2544
  }
2545
+
2546
+ observer.onNext(result);
2547
+ i++;
2548
+ self();
2375
2549
  });
2376
2550
  });
2377
2551
  };
2378
2552
 
2379
2553
  /**
2380
2554
  * Converts an array to an observable sequence, using an optional scheduler to enumerate the array.
2381
- *
2382
- * @example
2383
- * var res = Rx.Observable.fromArray([1,2,3]);
2384
- * var res = Rx.Observable.fromArray([1,2,3], Rx.Scheduler.timeout);
2555
+ * @deprecated use Observable.from or Observable.of
2385
2556
  * @param {Scheduler} [scheduler] Scheduler to run the enumeration of the input sequence on.
2386
2557
  * @returns {Observable} The observable sequence whose elements are pulled from the given enumerable sequence.
2387
2558
  */
2388
2559
  var observableFromArray = Observable.fromArray = function (array, scheduler) {
2560
+ deprecate('fromArray', 'from');
2389
2561
  isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2390
2562
  return new AnonymousObservable(function (observer) {
2391
2563
  var count = 0, len = array.length;
@@ -2443,29 +2615,36 @@ if (!Array.prototype.forEach) {
2443
2615
  });
2444
2616
  };
2445
2617
 
2618
+ function observableOf (scheduler, array) {
2619
+ isScheduler(scheduler) || (scheduler = currentThreadScheduler);
2620
+ return new AnonymousObservable(function (observer) {
2621
+ var count = 0, len = array.length;
2622
+ return scheduler.scheduleRecursive(function (self) {
2623
+ if (count < len) {
2624
+ observer.onNext(array[count++]);
2625
+ self();
2626
+ } else {
2627
+ observer.onCompleted();
2628
+ }
2629
+ });
2630
+ });
2631
+ }
2632
+
2446
2633
  /**
2447
2634
  * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2448
- * @example
2449
- * var res = Rx.Observable.of(1,2,3);
2450
2635
  * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2451
2636
  */
2452
2637
  Observable.of = function () {
2453
- var len = arguments.length, args = new Array(len);
2454
- for(var i = 0; i < len; i++) { args[i] = arguments[i]; }
2455
- return observableFromArray(args);
2638
+ return observableOf(null, arguments);
2456
2639
  };
2457
2640
 
2458
2641
  /**
2459
2642
  * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
2460
- * @example
2461
- * var res = Rx.Observable.of(1,2,3);
2462
2643
  * @param {Scheduler} scheduler A scheduler to use for scheduling the arguments.
2463
2644
  * @returns {Observable} The observable sequence whose elements are pulled from the given arguments.
2464
2645
  */
2465
- var observableOf = Observable.ofWithScheduler = function (scheduler) {
2466
- var len = arguments.length - 1, args = new Array(len);
2467
- for(var i = 0; i < len; i++) { args[i] = arguments[i + 1]; }
2468
- return observableFromArray(args, scheduler);
2646
+ Observable.ofWithScheduler = function (scheduler) {
2647
+ return observableOf(scheduler, slice.call(arguments, 1));
2469
2648
  };
2470
2649
 
2471
2650
  /**
@@ -2532,7 +2711,7 @@ if (!Array.prototype.forEach) {
2532
2711
  * @param {Scheduler} scheduler Scheduler to send the single element on. If not specified, defaults to Scheduler.immediate.
2533
2712
  * @returns {Observable} An observable sequence containing the single specified element.
2534
2713
  */
2535
- var observableReturn = Observable['return'] = Observable.returnValue = Observable.just = function (value, scheduler) {
2714
+ var observableReturn = Observable['return'] = Observable.just = function (value, scheduler) {
2536
2715
  isScheduler(scheduler) || (scheduler = immediateScheduler);
2537
2716
  return new AnonymousObservable(function (observer) {
2538
2717
  return scheduler.schedule(function () {
@@ -2542,6 +2721,12 @@ if (!Array.prototype.forEach) {
2542
2721
  });
2543
2722
  };
2544
2723
 
2724
+ /** @deprecated use return or just */
2725
+ Observable.returnValue = function () {
2726
+ deprecate('returnValue', 'return or just');
2727
+ return observableReturn.apply(null, arguments);
2728
+ };
2729
+
2545
2730
  /**
2546
2731
  * Returns an observable sequence that terminates with an exception, using the specified scheduler to send out the single onError message.
2547
2732
  * There is an alias to this method called 'throwError' for browsers <IE9.
@@ -2684,7 +2869,7 @@ if (!Array.prototype.forEach) {
2684
2869
  }, observer.onCompleted.bind(observer)));
2685
2870
 
2686
2871
  return subscription;
2687
- });
2872
+ }, source);
2688
2873
  }
2689
2874
 
2690
2875
  /**
@@ -2695,19 +2880,35 @@ if (!Array.prototype.forEach) {
2695
2880
  * @param {Mixed} handlerOrSecond Exception handler function that returns an observable sequence given the error that occurred in the first sequence, or a second observable sequence used to produce results when an error occurred in the first sequence.
2696
2881
  * @returns {Observable} An observable sequence containing the first sequence's elements, followed by the elements of the handler sequence in case an exception occurred.
2697
2882
  */
2698
- observableProto['catch'] = observableProto.catchError = observableProto.catchException = function (handlerOrSecond) {
2883
+ observableProto['catch'] = observableProto.catchError = function (handlerOrSecond) {
2699
2884
  return typeof handlerOrSecond === 'function' ?
2700
2885
  observableCatchHandler(this, handlerOrSecond) :
2701
2886
  observableCatch([this, handlerOrSecond]);
2702
2887
  };
2703
2888
 
2889
+ /**
2890
+ * @deprecated use #catch or #catchError instead.
2891
+ */
2892
+ observableProto.catchException = function (handlerOrSecond) {
2893
+ deprecate('catchException', 'catch or catchError');
2894
+ return this.catchError(handlerOrSecond);
2895
+ };
2896
+
2704
2897
  /**
2705
2898
  * Continues an observable sequence that is terminated by an exception with the next observable sequence.
2706
2899
  * @param {Array | Arguments} args Arguments or an array to use as the next sequence if an error occurs.
2707
2900
  * @returns {Observable} An observable sequence containing elements from consecutive source sequences until a source sequence terminates successfully.
2708
2901
  */
2709
- var observableCatch = Observable.catchException = Observable.catchError = Observable['catch'] = function () {
2710
- return enumerableOf(argsOrArray(arguments, 0)).catchException();
2902
+ var observableCatch = Observable.catchError = Observable['catch'] = function () {
2903
+ return enumerableOf(argsOrArray(arguments, 0)).catchError();
2904
+ };
2905
+
2906
+ /**
2907
+ * @deprecated use #catch or #catchError instead.
2908
+ */
2909
+ Observable.catchException = function () {
2910
+ deprecate('catchException', 'catch or catchError');
2911
+ return observableCatch.apply(null, arguments);
2711
2912
  };
2712
2913
 
2713
2914
  /**
@@ -2791,7 +2992,7 @@ if (!Array.prototype.forEach) {
2791
2992
  }
2792
2993
 
2793
2994
  return new CompositeDisposable(subscriptions);
2794
- });
2995
+ }, this);
2795
2996
  };
2796
2997
 
2797
2998
  /**
@@ -2817,13 +3018,19 @@ if (!Array.prototype.forEach) {
2817
3018
  return enumerableOf(argsOrArray(arguments, 0)).concat();
2818
3019
  };
2819
3020
 
2820
- /**
2821
- * Concatenates an observable sequence of observable sequences.
2822
- * @returns {Observable} An observable sequence that contains the elements of each observed inner sequence, in sequential order.
2823
- */
2824
- observableProto.concatObservable = observableProto.concatAll =function () {
2825
- return this.merge(1);
2826
- };
3021
+ /**
3022
+ * Concatenates an observable sequence of observable sequences.
3023
+ * @returns {Observable} An observable sequence that contains the elements of each observed inner sequence, in sequential order.
3024
+ */
3025
+ observableProto.concatAll = function () {
3026
+ return this.merge(1);
3027
+ };
3028
+
3029
+ /** @deprecated Use `concatAll` instead. */
3030
+ observableProto.concatObservable = function () {
3031
+ deprecate('concatObservable', 'concatAll');
3032
+ return this.merge(1);
3033
+ };
2827
3034
 
2828
3035
  /**
2829
3036
  * Merges an observable sequence of observable sequences into an observable sequence, limiting the number of concurrent subscriptions to inner sequences.
@@ -2870,43 +3077,37 @@ if (!Array.prototype.forEach) {
2870
3077
  activeCount === 0 && observer.onCompleted();
2871
3078
  }));
2872
3079
  return group;
2873
- });
3080
+ }, sources);
2874
3081
  };
2875
3082
 
2876
- /**
2877
- * Merges all the observable sequences into a single observable sequence.
2878
- * The scheduler is optional and if not specified, the immediate scheduler is used.
2879
- *
2880
- * @example
2881
- * 1 - merged = Rx.Observable.merge(xs, ys, zs);
2882
- * 2 - merged = Rx.Observable.merge([xs, ys, zs]);
2883
- * 3 - merged = Rx.Observable.merge(scheduler, xs, ys, zs);
2884
- * 4 - merged = Rx.Observable.merge(scheduler, [xs, ys, zs]);
2885
- * @returns {Observable} The observable sequence that merges the elements of the observable sequences.
2886
- */
2887
- var observableMerge = Observable.merge = function () {
2888
- var scheduler, sources;
2889
- if (!arguments[0]) {
2890
- scheduler = immediateScheduler;
2891
- sources = slice.call(arguments, 1);
2892
- } else if (arguments[0].now) {
2893
- scheduler = arguments[0];
2894
- sources = slice.call(arguments, 1);
2895
- } else {
2896
- scheduler = immediateScheduler;
2897
- sources = slice.call(arguments, 0);
2898
- }
2899
- if (Array.isArray(sources[0])) {
2900
- sources = sources[0];
2901
- }
2902
- return observableFromArray(sources, scheduler).mergeObservable();
2903
- };
3083
+ /**
3084
+ * Merges all the observable sequences into a single observable sequence.
3085
+ * The scheduler is optional and if not specified, the immediate scheduler is used.
3086
+ * @returns {Observable} The observable sequence that merges the elements of the observable sequences.
3087
+ */
3088
+ var observableMerge = Observable.merge = function () {
3089
+ var scheduler, sources;
3090
+ if (!arguments[0]) {
3091
+ scheduler = immediateScheduler;
3092
+ sources = slice.call(arguments, 1);
3093
+ } else if (isScheduler(arguments[0])) {
3094
+ scheduler = arguments[0];
3095
+ sources = slice.call(arguments, 1);
3096
+ } else {
3097
+ scheduler = immediateScheduler;
3098
+ sources = slice.call(arguments, 0);
3099
+ }
3100
+ if (Array.isArray(sources[0])) {
3101
+ sources = sources[0];
3102
+ }
3103
+ return observableOf(scheduler, sources).mergeAll();
3104
+ };
2904
3105
 
2905
3106
  /**
2906
3107
  * Merges an observable sequence of observable sequences into an observable sequence.
2907
3108
  * @returns {Observable} The observable sequence that merges the elements of the inner sequences.
2908
3109
  */
2909
- observableProto.mergeObservable = observableProto.mergeAll = function () {
3110
+ observableProto.mergeAll = function () {
2910
3111
  var sources = this;
2911
3112
  return new AnonymousObservable(function (observer) {
2912
3113
  var group = new CompositeDisposable(),
@@ -2930,7 +3131,15 @@ if (!Array.prototype.forEach) {
2930
3131
  group.length === 1 && observer.onCompleted();
2931
3132
  }));
2932
3133
  return group;
2933
- });
3134
+ }, sources);
3135
+ };
3136
+
3137
+ /**
3138
+ * @deprecated use #mergeAll instead.
3139
+ */
3140
+ observableProto.mergeObservable = function () {
3141
+ deprecate('mergeObservable', 'mergeAll');
3142
+ return this.mergeAll.apply(this, arguments);
2934
3143
  };
2935
3144
 
2936
3145
  /**
@@ -2998,7 +3207,7 @@ if (!Array.prototype.forEach) {
2998
3207
  }));
2999
3208
 
3000
3209
  return disposables;
3001
- });
3210
+ }, source);
3002
3211
  };
3003
3212
 
3004
3213
  /**
@@ -3037,7 +3246,7 @@ if (!Array.prototype.forEach) {
3037
3246
  !hasLatest && observer.onCompleted();
3038
3247
  });
3039
3248
  return new CompositeDisposable(subscription, innerSubscription);
3040
- });
3249
+ }, sources);
3041
3250
  };
3042
3251
 
3043
3252
  /**
@@ -3053,7 +3262,7 @@ if (!Array.prototype.forEach) {
3053
3262
  source.subscribe(observer),
3054
3263
  other.subscribe(observer.onCompleted.bind(observer), observer.onError.bind(observer), noop)
3055
3264
  );
3056
- });
3265
+ }, source);
3057
3266
  };
3058
3267
 
3059
3268
  function zipArray(second, resultSelector) {
@@ -3074,7 +3283,7 @@ if (!Array.prototype.forEach) {
3074
3283
  observer.onCompleted();
3075
3284
  }
3076
3285
  }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3077
- });
3286
+ }, first);
3078
3287
  }
3079
3288
 
3080
3289
  /**
@@ -3136,7 +3345,7 @@ if (!Array.prototype.forEach) {
3136
3345
  }
3137
3346
 
3138
3347
  return new CompositeDisposable(subscriptions);
3139
- });
3348
+ }, parent);
3140
3349
  };
3141
3350
 
3142
3351
  /**
@@ -3206,7 +3415,7 @@ if (!Array.prototype.forEach) {
3206
3415
  * @returns {Observable} An observable sequence that hides the identity of the source sequence.
3207
3416
  */
3208
3417
  observableProto.asObservable = function () {
3209
- return new AnonymousObservable(this.subscribe.bind(this));
3418
+ return new AnonymousObservable(this.subscribe.bind(this), this);
3210
3419
  };
3211
3420
 
3212
3421
  /**
@@ -3230,60 +3439,58 @@ if (!Array.prototype.forEach) {
3230
3439
  });
3231
3440
  };
3232
3441
 
3233
- /**
3234
- * Dematerializes the explicit notification values of an observable sequence as implicit notifications.
3235
- * @returns {Observable} An observable sequence exhibiting the behavior corresponding to the source sequence's notification values.
3236
- */
3237
- observableProto.dematerialize = function () {
3238
- var source = this;
3239
- return new AnonymousObservable(function (observer) {
3240
- return source.subscribe(function (x) {
3241
- return x.accept(observer);
3242
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3243
- });
3244
- };
3442
+ /**
3443
+ * Dematerializes the explicit notification values of an observable sequence as implicit notifications.
3444
+ * @returns {Observable} An observable sequence exhibiting the behavior corresponding to the source sequence's notification values.
3445
+ */
3446
+ observableProto.dematerialize = function () {
3447
+ var source = this;
3448
+ return new AnonymousObservable(function (observer) {
3449
+ return source.subscribe(function (x) { return x.accept(observer); }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3450
+ }, this);
3451
+ };
3245
3452
 
3246
- /**
3247
- * Returns an observable sequence that contains only distinct contiguous elements according to the keySelector and the comparer.
3248
- *
3249
- * var obs = observable.distinctUntilChanged();
3250
- * var obs = observable.distinctUntilChanged(function (x) { return x.id; });
3251
- * var obs = observable.distinctUntilChanged(function (x) { return x.id; }, function (x, y) { return x === y; });
3252
- *
3253
- * @param {Function} [keySelector] A function to compute the comparison key for each element. If not provided, it projects the value.
3254
- * @param {Function} [comparer] Equality comparer for computed key values. If not provided, defaults to an equality comparer function.
3255
- * @returns {Observable} An observable sequence only containing the distinct contiguous elements, based on a computed key value, from the source sequence.
3256
- */
3257
- observableProto.distinctUntilChanged = function (keySelector, comparer) {
3258
- var source = this;
3259
- keySelector || (keySelector = identity);
3260
- comparer || (comparer = defaultComparer);
3261
- return new AnonymousObservable(function (observer) {
3262
- var hasCurrentKey = false, currentKey;
3263
- return source.subscribe(function (value) {
3264
- var comparerEquals = false, key;
3265
- try {
3266
- key = keySelector(value);
3267
- } catch (exception) {
3268
- observer.onError(exception);
3269
- return;
3270
- }
3271
- if (hasCurrentKey) {
3272
- try {
3273
- comparerEquals = comparer(currentKey, key);
3274
- } catch (exception) {
3275
- observer.onError(exception);
3276
- return;
3277
- }
3278
- }
3279
- if (!hasCurrentKey || !comparerEquals) {
3280
- hasCurrentKey = true;
3281
- currentKey = key;
3282
- observer.onNext(value);
3283
- }
3284
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3285
- });
3286
- };
3453
+ /**
3454
+ * Returns an observable sequence that contains only distinct contiguous elements according to the keySelector and the comparer.
3455
+ *
3456
+ * var obs = observable.distinctUntilChanged();
3457
+ * var obs = observable.distinctUntilChanged(function (x) { return x.id; });
3458
+ * var obs = observable.distinctUntilChanged(function (x) { return x.id; }, function (x, y) { return x === y; });
3459
+ *
3460
+ * @param {Function} [keySelector] A function to compute the comparison key for each element. If not provided, it projects the value.
3461
+ * @param {Function} [comparer] Equality comparer for computed key values. If not provided, defaults to an equality comparer function.
3462
+ * @returns {Observable} An observable sequence only containing the distinct contiguous elements, based on a computed key value, from the source sequence.
3463
+ */
3464
+ observableProto.distinctUntilChanged = function (keySelector, comparer) {
3465
+ var source = this;
3466
+ keySelector || (keySelector = identity);
3467
+ comparer || (comparer = defaultComparer);
3468
+ return new AnonymousObservable(function (observer) {
3469
+ var hasCurrentKey = false, currentKey;
3470
+ return source.subscribe(function (value) {
3471
+ var comparerEquals = false, key;
3472
+ try {
3473
+ key = keySelector(value);
3474
+ } catch (e) {
3475
+ observer.onError(e);
3476
+ return;
3477
+ }
3478
+ if (hasCurrentKey) {
3479
+ try {
3480
+ comparerEquals = comparer(currentKey, key);
3481
+ } catch (e) {
3482
+ observer.onError(e);
3483
+ return;
3484
+ }
3485
+ }
3486
+ if (!hasCurrentKey || !comparerEquals) {
3487
+ hasCurrentKey = true;
3488
+ currentKey = key;
3489
+ observer.onNext(value);
3490
+ }
3491
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3492
+ }, this);
3493
+ };
3287
3494
 
3288
3495
  /**
3289
3496
  * Invokes an action for each element in the observable sequence and invokes an action upon graceful or exceptional termination of the observable sequence.
@@ -3293,7 +3500,7 @@ if (!Array.prototype.forEach) {
3293
3500
  * @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence. Used if only the observerOrOnNext parameter is also a function.
3294
3501
  * @returns {Observable} The source sequence with the side-effecting behavior applied.
3295
3502
  */
3296
- observableProto['do'] = observableProto.doAction = observableProto.tap = function (observerOrOnNext, onError, onCompleted) {
3503
+ observableProto['do'] = observableProto.tap = function (observerOrOnNext, onError, onCompleted) {
3297
3504
  var source = this, onNextFunc;
3298
3505
  if (typeof observerOrOnNext === 'function') {
3299
3506
  onNextFunc = observerOrOnNext;
@@ -3329,7 +3536,13 @@ if (!Array.prototype.forEach) {
3329
3536
  }
3330
3537
  observer.onCompleted();
3331
3538
  });
3332
- });
3539
+ }, this);
3540
+ };
3541
+
3542
+ /** @deprecated use #do or #tap instead. */
3543
+ observableProto.doAction = function () {
3544
+ deprecate('doAction', 'do or tap');
3545
+ return this.tap.apply(this, arguments);
3333
3546
  };
3334
3547
 
3335
3548
  /**
@@ -3367,13 +3580,10 @@ if (!Array.prototype.forEach) {
3367
3580
 
3368
3581
  /**
3369
3582
  * Invokes a specified action after the source observable sequence terminates gracefully or exceptionally.
3370
- *
3371
- * @example
3372
- * var res = observable.finallyAction(function () { console.log('sequence ended'; });
3373
3583
  * @param {Function} finallyAction Action to invoke after the source observable sequence terminates.
3374
3584
  * @returns {Observable} Source sequence with the action-invoking termination behavior applied.
3375
3585
  */
3376
- observableProto['finally'] = observableProto.finallyAction = function (action) {
3586
+ observableProto['finally'] = observableProto.ensure = function (action) {
3377
3587
  var source = this;
3378
3588
  return new AnonymousObservable(function (observer) {
3379
3589
  var subscription;
@@ -3392,7 +3602,15 @@ if (!Array.prototype.forEach) {
3392
3602
  action();
3393
3603
  }
3394
3604
  });
3395
- });
3605
+ }, this);
3606
+ };
3607
+
3608
+ /**
3609
+ * @deprecated use #finally or #ensure instead.
3610
+ */
3611
+ observableProto.finallyAction = function (action) {
3612
+ deprecate('finallyAction', 'finally or ensure');
3613
+ return this.ensure(action);
3396
3614
  };
3397
3615
 
3398
3616
  /**
@@ -3403,7 +3621,7 @@ if (!Array.prototype.forEach) {
3403
3621
  var source = this;
3404
3622
  return new AnonymousObservable(function (observer) {
3405
3623
  return source.subscribe(noop, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3406
- });
3624
+ }, source);
3407
3625
  };
3408
3626
 
3409
3627
  /**
@@ -3422,21 +3640,17 @@ if (!Array.prototype.forEach) {
3422
3640
  observer.onNext(notificationCreateOnCompleted());
3423
3641
  observer.onCompleted();
3424
3642
  });
3425
- });
3643
+ }, source);
3426
3644
  };
3427
3645
 
3428
- /**
3429
- * Repeats the observable sequence a specified number of times. If the repeat count is not specified, the sequence repeats indefinitely.
3430
- *
3431
- * @example
3432
- * var res = repeated = source.repeat();
3433
- * var res = repeated = source.repeat(42);
3434
- * @param {Number} [repeatCount] Number of times to repeat the sequence. If not provided, repeats the sequence indefinitely.
3435
- * @returns {Observable} The observable sequence producing the elements of the given sequence repeatedly.
3436
- */
3437
- observableProto.repeat = function (repeatCount) {
3438
- return enumerableRepeat(this, repeatCount).concat();
3439
- };
3646
+ /**
3647
+ * Repeats the observable sequence a specified number of times. If the repeat count is not specified, the sequence repeats indefinitely.
3648
+ * @param {Number} [repeatCount] Number of times to repeat the sequence. If not provided, repeats the sequence indefinitely.
3649
+ * @returns {Observable} The observable sequence producing the elements of the given sequence repeatedly.
3650
+ */
3651
+ observableProto.repeat = function (repeatCount) {
3652
+ return enumerableRepeat(this, repeatCount).concat();
3653
+ };
3440
3654
 
3441
3655
  /**
3442
3656
  * Repeats the source observable sequence the specified number of times or until it successfully terminates. If the retry count is not specified, it retries indefinitely.
@@ -3449,7 +3663,7 @@ if (!Array.prototype.forEach) {
3449
3663
  * @returns {Observable} An observable sequence producing the elements of the given sequence repeatedly until it terminates successfully.
3450
3664
  */
3451
3665
  observableProto.retry = function (retryCount) {
3452
- return enumerableRepeat(this, retryCount).catchException();
3666
+ return enumerableRepeat(this, retryCount).catchError();
3453
3667
  };
3454
3668
 
3455
3669
  /**
@@ -3496,7 +3710,7 @@ if (!Array.prototype.forEach) {
3496
3710
  observer.onCompleted();
3497
3711
  }
3498
3712
  );
3499
- });
3713
+ }, source);
3500
3714
  };
3501
3715
 
3502
3716
  /**
@@ -3515,7 +3729,7 @@ if (!Array.prototype.forEach) {
3515
3729
  q.push(x);
3516
3730
  q.length > count && observer.onNext(q.shift());
3517
3731
  }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3518
- });
3732
+ }, source);
3519
3733
  };
3520
3734
 
3521
3735
  /**
@@ -3554,10 +3768,10 @@ if (!Array.prototype.forEach) {
3554
3768
  q.push(x);
3555
3769
  q.length > count && q.shift();
3556
3770
  }, observer.onError.bind(observer), function () {
3557
- while(q.length > 0) { observer.onNext(q.shift()); }
3771
+ while (q.length > 0) { observer.onNext(q.shift()); }
3558
3772
  observer.onCompleted();
3559
3773
  });
3560
- });
3774
+ }, source);
3561
3775
  };
3562
3776
 
3563
3777
  /**
@@ -3580,7 +3794,7 @@ if (!Array.prototype.forEach) {
3580
3794
  observer.onNext(q);
3581
3795
  observer.onCompleted();
3582
3796
  });
3583
- });
3797
+ }, source);
3584
3798
  };
3585
3799
 
3586
3800
  /**
@@ -3620,27 +3834,27 @@ if (!Array.prototype.forEach) {
3620
3834
  function (x) {
3621
3835
  for (var i = 0, len = q.length; i < len; i++) { q[i].onNext(x); }
3622
3836
  var c = n - count + 1;
3623
- c >=0 && c % skip === 0 && q.shift().onCompleted();
3837
+ c >= 0 && c % skip === 0 && q.shift().onCompleted();
3624
3838
  ++n % skip === 0 && createWindow();
3625
- },
3839
+ },
3626
3840
  function (e) {
3627
3841
  while (q.length > 0) { q.shift().onError(e); }
3628
3842
  observer.onError(e);
3629
- },
3843
+ },
3630
3844
  function () {
3631
3845
  while (q.length > 0) { q.shift().onCompleted(); }
3632
3846
  observer.onCompleted();
3633
3847
  }
3634
3848
  ));
3635
3849
  return refCountDisposable;
3636
- });
3850
+ }, source);
3637
3851
  };
3638
3852
 
3639
3853
  function concatMap(source, selector, thisArg) {
3640
3854
  return source.map(function (x, i) {
3641
3855
  var result = selector.call(thisArg, x, i, source);
3642
3856
  isPromise(result) && (result = observableFromPromise(result));
3643
- (Array.isArray(result) || isIterable(result)) && (result = observableFrom(result));
3857
+ (isArrayLike(result) || isIterable(result)) && (result = observableFrom(result));
3644
3858
  return result;
3645
3859
  }).concatAll();
3646
3860
  }
@@ -3665,18 +3879,18 @@ if (!Array.prototype.forEach) {
3665
3879
  * @returns {Observable} An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element.
3666
3880
  */
3667
3881
  observableProto.selectConcat = observableProto.concatMap = function (selector, resultSelector, thisArg) {
3668
- if (typeof selector === 'function' && typeof resultSelector === 'function') {
3882
+ if (isFunction(selector) && isFunction(resultSelector)) {
3669
3883
  return this.concatMap(function (x, i) {
3670
3884
  var selectorResult = selector(x, i);
3671
3885
  isPromise(selectorResult) && (selectorResult = observableFromPromise(selectorResult));
3672
- (Array.isArray(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
3886
+ (isArrayLike(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
3673
3887
 
3674
3888
  return selectorResult.map(function (y, i2) {
3675
3889
  return resultSelector(x, y, i, i2);
3676
3890
  });
3677
3891
  });
3678
3892
  }
3679
- return typeof selector === 'function' ?
3893
+ return isFunction(selector) ?
3680
3894
  concatMap(this, selector, thisArg) :
3681
3895
  concatMap(this, function () { return selector; });
3682
3896
  };
@@ -3730,7 +3944,7 @@ if (!Array.prototype.forEach) {
3730
3944
  observer.onNext(result);
3731
3945
  observer.onCompleted();
3732
3946
  });
3733
- }).concatAll();
3947
+ }, this).concatAll();
3734
3948
  };
3735
3949
 
3736
3950
  /**
@@ -3744,22 +3958,18 @@ if (!Array.prototype.forEach) {
3744
3958
  * @returns {Observable} An observable sequence that contains the specified default value if the source is empty; otherwise, the elements of the source itself.
3745
3959
  */
3746
3960
  observableProto.defaultIfEmpty = function (defaultValue) {
3747
- var source = this;
3748
- if (defaultValue === undefined) {
3749
- defaultValue = null;
3750
- }
3751
- return new AnonymousObservable(function (observer) {
3752
- var found = false;
3753
- return source.subscribe(function (x) {
3754
- found = true;
3755
- observer.onNext(x);
3756
- }, observer.onError.bind(observer), function () {
3757
- if (!found) {
3758
- observer.onNext(defaultValue);
3759
- }
3760
- observer.onCompleted();
3761
- });
3961
+ var source = this;
3962
+ defaultValue === undefined && (defaultValue = null);
3963
+ return new AnonymousObservable(function (observer) {
3964
+ var found = false;
3965
+ return source.subscribe(function (x) {
3966
+ found = true;
3967
+ observer.onNext(x);
3968
+ }, observer.onError.bind(observer), function () {
3969
+ !found && observer.onNext(defaultValue);
3970
+ observer.onCompleted();
3762
3971
  });
3972
+ }, this);
3763
3973
  };
3764
3974
 
3765
3975
  // Swap out for Array.findIndex
@@ -3812,7 +4022,7 @@ if (!Array.prototype.forEach) {
3812
4022
  },
3813
4023
  observer.onError.bind(observer),
3814
4024
  observer.onCompleted.bind(observer));
3815
- });
4025
+ }, this);
3816
4026
  };
3817
4027
 
3818
4028
  /**
@@ -3926,30 +4136,31 @@ if (!Array.prototype.forEach) {
3926
4136
  }));
3927
4137
 
3928
4138
  return refCountDisposable;
3929
- });
4139
+ }, source);
3930
4140
  };
3931
4141
 
3932
4142
  /**
3933
- * Projects each element of an observable sequence into a new form by incorporating the element's index.
4143
+ * Projects each element of an observable sequence into a new form by incorporating the element's index.
3934
4144
  * @param {Function} selector A transform function to apply to each source element; the second parameter of the function represents the index of the source element.
3935
4145
  * @param {Any} [thisArg] Object to use as this when executing callback.
3936
4146
  * @returns {Observable} An observable sequence whose elements are the result of invoking the transform function on each element of source.
3937
4147
  */
3938
4148
  observableProto.select = observableProto.map = function (selector, thisArg) {
3939
- var parent = this;
4149
+ var selectorFn = isFunction(selector) ? selector : function () { return selector; },
4150
+ source = this;
3940
4151
  return new AnonymousObservable(function (observer) {
3941
4152
  var count = 0;
3942
- return parent.subscribe(function (value) {
4153
+ return source.subscribe(function (value) {
3943
4154
  var result;
3944
4155
  try {
3945
- result = selector.call(thisArg, value, count++, parent);
4156
+ result = selectorFn.call(thisArg, value, count++, source);
3946
4157
  } catch (e) {
3947
4158
  observer.onError(e);
3948
4159
  return;
3949
4160
  }
3950
4161
  observer.onNext(result);
3951
4162
  }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
3952
- });
4163
+ }, source);
3953
4164
  };
3954
4165
 
3955
4166
  /**
@@ -3965,9 +4176,9 @@ if (!Array.prototype.forEach) {
3965
4176
  return source.map(function (x, i) {
3966
4177
  var result = selector.call(thisArg, x, i, source);
3967
4178
  isPromise(result) && (result = observableFromPromise(result));
3968
- (Array.isArray(result) || isIterable(result)) && (result = observableFrom(result));
4179
+ (isArrayLike(result) || isIterable(result)) && (result = observableFrom(result));
3969
4180
  return result;
3970
- }).mergeObservable();
4181
+ }).mergeAll();
3971
4182
  }
3972
4183
 
3973
4184
  /**
@@ -3990,18 +4201,18 @@ if (!Array.prototype.forEach) {
3990
4201
  * @returns {Observable} An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element.
3991
4202
  */
3992
4203
  observableProto.selectMany = observableProto.flatMap = function (selector, resultSelector, thisArg) {
3993
- if (typeof selector === 'function' && typeof resultSelector === 'function') {
4204
+ if (isFunction(selector) && isFunction(resultSelector)) {
3994
4205
  return this.flatMap(function (x, i) {
3995
4206
  var selectorResult = selector(x, i);
3996
4207
  isPromise(selectorResult) && (selectorResult = observableFromPromise(selectorResult));
3997
- (Array.isArray(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
4208
+ (isArrayLike(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
3998
4209
 
3999
4210
  return selectorResult.map(function (y, i2) {
4000
4211
  return resultSelector(x, y, i, i2);
4001
4212
  });
4002
4213
  }, thisArg);
4003
4214
  }
4004
- return typeof selector === 'function' ?
4215
+ return isFunction(selector) ?
4005
4216
  flatMap(this, selector, thisArg) :
4006
4217
  flatMap(this, function () { return selector; });
4007
4218
  };
@@ -4055,7 +4266,7 @@ if (!Array.prototype.forEach) {
4055
4266
  observer.onNext(result);
4056
4267
  observer.onCompleted();
4057
4268
  });
4058
- }).mergeAll();
4269
+ }, source).mergeAll();
4059
4270
  };
4060
4271
 
4061
4272
  /**
@@ -4076,18 +4287,18 @@ if (!Array.prototype.forEach) {
4076
4287
  * @returns {Observable} An observable sequence that contains the elements that occur after the specified index in the input sequence.
4077
4288
  */
4078
4289
  observableProto.skip = function (count) {
4079
- if (count < 0) { throw new Error(argumentOutOfRange); }
4080
- var source = this;
4081
- return new AnonymousObservable(function (observer) {
4082
- var remaining = count;
4083
- return source.subscribe(function (x) {
4084
- if (remaining <= 0) {
4085
- observer.onNext(x);
4086
- } else {
4087
- remaining--;
4088
- }
4089
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4090
- });
4290
+ if (count < 0) { throw new Error(argumentOutOfRange); }
4291
+ var source = this;
4292
+ return new AnonymousObservable(function (observer) {
4293
+ var remaining = count;
4294
+ return source.subscribe(function (x) {
4295
+ if (remaining <= 0) {
4296
+ observer.onNext(x);
4297
+ } else {
4298
+ remaining--;
4299
+ }
4300
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4301
+ }, source);
4091
4302
  };
4092
4303
 
4093
4304
  /**
@@ -4115,7 +4326,7 @@ if (!Array.prototype.forEach) {
4115
4326
  }
4116
4327
  running && observer.onNext(x);
4117
4328
  }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4118
- });
4329
+ }, source);
4119
4330
  };
4120
4331
 
4121
4332
  /**
@@ -4128,18 +4339,18 @@ if (!Array.prototype.forEach) {
4128
4339
  * @returns {Observable} An observable sequence that contains the specified number of elements from the start of the input sequence.
4129
4340
  */
4130
4341
  observableProto.take = function (count, scheduler) {
4131
- if (count < 0) { throw new RangeError(argumentOutOfRange); }
4132
- if (count === 0) { return observableEmpty(scheduler); }
4133
- var observable = this;
4134
- return new AnonymousObservable(function (observer) {
4135
- var remaining = count;
4136
- return observable.subscribe(function (x) {
4137
- if (remaining-- > 0) {
4138
- observer.onNext(x);
4139
- remaining === 0 && observer.onCompleted();
4140
- }
4141
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4142
- });
4342
+ if (count < 0) { throw new RangeError(argumentOutOfRange); }
4343
+ if (count === 0) { return observableEmpty(scheduler); }
4344
+ var source = this;
4345
+ return new AnonymousObservable(function (observer) {
4346
+ var remaining = count;
4347
+ return source.subscribe(function (x) {
4348
+ if (remaining-- > 0) {
4349
+ observer.onNext(x);
4350
+ remaining === 0 && observer.onCompleted();
4351
+ }
4352
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4353
+ }, source);
4143
4354
  };
4144
4355
 
4145
4356
  /**
@@ -4150,13 +4361,13 @@ if (!Array.prototype.forEach) {
4150
4361
  * @returns {Observable} An observable sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.
4151
4362
  */
4152
4363
  observableProto.takeWhile = function (predicate, thisArg) {
4153
- var observable = this;
4364
+ var source = this;
4154
4365
  return new AnonymousObservable(function (observer) {
4155
4366
  var i = 0, running = true;
4156
- return observable.subscribe(function (x) {
4367
+ return source.subscribe(function (x) {
4157
4368
  if (running) {
4158
4369
  try {
4159
- running = predicate.call(thisArg, x, i++, observable);
4370
+ running = predicate.call(thisArg, x, i++, source);
4160
4371
  } catch (e) {
4161
4372
  observer.onError(e);
4162
4373
  return;
@@ -4168,7 +4379,7 @@ if (!Array.prototype.forEach) {
4168
4379
  }
4169
4380
  }
4170
4381
  }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4171
- });
4382
+ }, source);
4172
4383
  };
4173
4384
 
4174
4385
  /**
@@ -4182,20 +4393,20 @@ if (!Array.prototype.forEach) {
4182
4393
  * @returns {Observable} An observable sequence that contains elements from the input sequence that satisfy the condition.
4183
4394
  */
4184
4395
  observableProto.where = observableProto.filter = function (predicate, thisArg) {
4185
- var parent = this;
4186
- return new AnonymousObservable(function (observer) {
4187
- var count = 0;
4188
- return parent.subscribe(function (value) {
4189
- var shouldRun;
4190
- try {
4191
- shouldRun = predicate.call(thisArg, value, count++, parent);
4192
- } catch (e) {
4193
- observer.onError(e);
4194
- return;
4195
- }
4196
- shouldRun && observer.onNext(value);
4197
- }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4198
- });
4396
+ var source = this;
4397
+ return new AnonymousObservable(function (observer) {
4398
+ var count = 0;
4399
+ return source.subscribe(function (value) {
4400
+ var shouldRun;
4401
+ try {
4402
+ shouldRun = predicate.call(thisArg, value, count++, parent);
4403
+ } catch (e) {
4404
+ observer.onError(e);
4405
+ return;
4406
+ }
4407
+ shouldRun && observer.onNext(value);
4408
+ }, observer.onError.bind(observer), observer.onCompleted.bind(observer));
4409
+ }, source);
4199
4410
  };
4200
4411
 
4201
4412
  observableProto.finalValue = function () {
@@ -4213,7 +4424,7 @@ if (!Array.prototype.forEach) {
4213
4424
  observer.onCompleted();
4214
4425
  }
4215
4426
  });
4216
- });
4427
+ }, source);
4217
4428
  };
4218
4429
 
4219
4430
  function extremaBy(source, keySelector, comparer) {
@@ -4248,24 +4459,24 @@ if (!Array.prototype.forEach) {
4248
4459
  observer.onNext(list);
4249
4460
  observer.onCompleted();
4250
4461
  });
4251
- });
4462
+ }, source);
4252
4463
  }
4253
4464
 
4254
- function firstOnly(x) {
4255
- if (x.length === 0) {
4256
- throw new Error(sequenceContainsNoElements);
4257
- }
4258
- return x[0];
4259
- }
4465
+ function firstOnly(x) {
4466
+ if (x.length === 0) { throw new Error(sequenceContainsNoElements); }
4467
+ return x[0];
4468
+ }
4260
4469
 
4261
4470
  /**
4262
4471
  * Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specified seed value is used as the initial accumulator value.
4263
4472
  * For aggregation behavior with incremental intermediate results, see Observable.scan.
4473
+ * @deprecated Use #reduce instead
4264
4474
  * @param {Mixed} [seed] The initial accumulator value.
4265
4475
  * @param {Function} accumulator An accumulator function to be invoked on each element.
4266
4476
  * @returns {Observable} An observable sequence containing a single element with the final accumulator value.
4267
4477
  */
4268
4478
  observableProto.aggregate = function () {
4479
+ deprecate('aggregate', 'reduce');
4269
4480
  var seed, hasSeed, accumulator;
4270
4481
  if (arguments.length === 2) {
4271
4482
  seed = arguments[0];
@@ -4293,28 +4504,31 @@ if (!Array.prototype.forEach) {
4293
4504
  return hasSeed ? this.scan(seed, accumulator).startWith(seed).finalValue() : this.scan(accumulator).finalValue();
4294
4505
  };
4295
4506
 
4296
- /**
4297
- * Determines whether any element of an observable sequence satisfies a condition if present, else if any items are in the sequence.
4298
- * @example
4299
- * var result = source.any();
4300
- * var result = source.any(function (x) { return x > 3; });
4301
- * @param {Function} [predicate] A function to test each element for a condition.
4302
- * @returns {Observable} An observable sequence containing a single element determining whether any elements in the source sequence pass the test in the specified predicate if given, else if any items are in the sequence.
4303
- */
4304
- observableProto.some = observableProto.any = function (predicate, thisArg) {
4305
- var source = this;
4306
- return predicate ?
4307
- source.where(predicate, thisArg).any() :
4308
- new AnonymousObservable(function (observer) {
4309
- return source.subscribe(function () {
4310
- observer.onNext(true);
4311
- observer.onCompleted();
4312
- }, observer.onError.bind(observer), function () {
4313
- observer.onNext(false);
4314
- observer.onCompleted();
4315
- });
4316
- });
4317
- };
4507
+ /**
4508
+ * Determines whether any element of an observable sequence satisfies a condition if present, else if any items are in the sequence.
4509
+ * @param {Function} [predicate] A function to test each element for a condition.
4510
+ * @returns {Observable} An observable sequence containing a single element determining whether any elements in the source sequence pass the test in the specified predicate if given, else if any items are in the sequence.
4511
+ */
4512
+ observableProto.some = function (predicate, thisArg) {
4513
+ var source = this;
4514
+ return predicate ?
4515
+ source.filter(predicate, thisArg).some() :
4516
+ new AnonymousObservable(function (observer) {
4517
+ return source.subscribe(function () {
4518
+ observer.onNext(true);
4519
+ observer.onCompleted();
4520
+ }, observer.onError.bind(observer), function () {
4521
+ observer.onNext(false);
4522
+ observer.onCompleted();
4523
+ });
4524
+ }, source);
4525
+ };
4526
+
4527
+ /** @deprecated use #some instead */
4528
+ observableProto.any = function () {
4529
+ deprecate('any', 'some');
4530
+ return this.some.apply(this, arguments);
4531
+ };
4318
4532
 
4319
4533
  /**
4320
4534
  * Determines whether an observable sequence is empty.
@@ -4324,22 +4538,21 @@ if (!Array.prototype.forEach) {
4324
4538
  return this.any().map(not);
4325
4539
  };
4326
4540
 
4327
- /**
4328
- * Determines whether all elements of an observable sequence satisfy a condition.
4329
- *
4330
- * 1 - res = source.all(function (value) { return value.length > 3; });
4331
- * @memberOf Observable#
4332
- * @param {Function} [predicate] A function to test each element for a condition.
4333
- * @param {Any} [thisArg] Object to use as this when executing callback.
4334
- * @returns {Observable} An observable sequence containing a single element determining whether all elements in the source sequence pass the test in the specified predicate.
4335
- */
4336
- observableProto.every = observableProto.all = function (predicate, thisArg) {
4337
- return this.where(function (v) {
4338
- return !predicate(v);
4339
- }, thisArg).any().select(function (b) {
4340
- return !b;
4341
- });
4342
- };
4541
+ /**
4542
+ * Determines whether all elements of an observable sequence satisfy a condition.
4543
+ * @param {Function} [predicate] A function to test each element for a condition.
4544
+ * @param {Any} [thisArg] Object to use as this when executing callback.
4545
+ * @returns {Observable} An observable sequence containing a single element determining whether all elements in the source sequence pass the test in the specified predicate.
4546
+ */
4547
+ observableProto.every = function (predicate, thisArg) {
4548
+ return this.filter(function (v) { return !predicate(v); }, thisArg).some().map(not);
4549
+ };
4550
+
4551
+ /** @deprecated use #every instead */
4552
+ observableProto.all = function () {
4553
+ deprecate('all', 'every');
4554
+ return this.every.apply(this, arguments);
4555
+ };
4343
4556
 
4344
4557
  /**
4345
4558
  * Determines whether an observable sequence contains a specified element with an optional equality comparer.
@@ -4372,7 +4585,7 @@ if (!Array.prototype.forEach) {
4372
4585
  observer.onNext(false);
4373
4586
  observer.onCompleted();
4374
4587
  });
4375
- });
4588
+ }, this);
4376
4589
  };
4377
4590
 
4378
4591
  /**
@@ -4421,13 +4634,11 @@ if (!Array.prototype.forEach) {
4421
4634
  observer.onNext(-1);
4422
4635
  observer.onCompleted();
4423
4636
  });
4424
- });
4637
+ }, source);
4425
4638
  };
4639
+
4426
4640
  /**
4427
4641
  * Computes the sum of a sequence of values that are obtained by invoking an optional transform function on each element of the input sequence, else if not specified computes the sum on each item in the sequence.
4428
- * @example
4429
- * var res = source.sum();
4430
- * var res = source.sum(function (x) { return x.value; });
4431
4642
  * @param {Function} [selector] A transform function to apply to each element.
4432
4643
  * @param {Any} [thisArg] Object to use as this when executing callback.
4433
4644
  * @returns {Observable} An observable sequence containing a single element with the sum of the values in the source sequence.
@@ -4435,68 +4646,62 @@ if (!Array.prototype.forEach) {
4435
4646
  observableProto.sum = function (keySelector, thisArg) {
4436
4647
  return keySelector && isFunction(keySelector) ?
4437
4648
  this.map(keySelector, thisArg).sum() :
4438
- this.aggregate(0, function (prev, curr) {
4649
+ this.reduce(function (prev, curr) {
4439
4650
  return prev + curr;
4440
- });
4651
+ }, 0);
4441
4652
  };
4442
4653
 
4443
- /**
4444
- * Returns the elements in an observable sequence with the minimum key value according to the specified comparer.
4445
- * @example
4446
- * var res = source.minBy(function (x) { return x.value; });
4447
- * var res = source.minBy(function (x) { return x.value; }, function (x, y) { return x - y; });
4448
- * @param {Function} keySelector Key selector function.
4449
- * @param {Function} [comparer] Comparer used to compare key values.
4450
- * @returns {Observable} An observable sequence containing a list of zero or more elements that have a minimum key value.
4451
- */
4452
- observableProto.minBy = function (keySelector, comparer) {
4453
- comparer || (comparer = defaultSubComparer);
4454
- return extremaBy(this, keySelector, function (x, y) {
4455
- return comparer(x, y) * -1;
4456
- });
4457
- };
4654
+ /**
4655
+ * Returns the elements in an observable sequence with the minimum key value according to the specified comparer.
4656
+ * @example
4657
+ * var res = source.minBy(function (x) { return x.value; });
4658
+ * var res = source.minBy(function (x) { return x.value; }, function (x, y) { return x - y; });
4659
+ * @param {Function} keySelector Key selector function.
4660
+ * @param {Function} [comparer] Comparer used to compare key values.
4661
+ * @returns {Observable} An observable sequence containing a list of zero or more elements that have a minimum key value.
4662
+ */
4663
+ observableProto.minBy = function (keySelector, comparer) {
4664
+ comparer || (comparer = defaultSubComparer);
4665
+ return extremaBy(this, keySelector, function (x, y) { return comparer(x, y) * -1; });
4666
+ };
4458
4667
 
4459
- /**
4460
- * Returns the minimum element in an observable sequence according to the optional comparer else a default greater than less than check.
4461
- * @example
4462
- * var res = source.min();
4463
- * var res = source.min(function (x, y) { return x.value - y.value; });
4464
- * @param {Function} [comparer] Comparer used to compare elements.
4465
- * @returns {Observable} An observable sequence containing a single element with the minimum element in the source sequence.
4466
- */
4467
- observableProto.min = function (comparer) {
4468
- return this.minBy(identity, comparer).select(function (x) {
4469
- return firstOnly(x);
4470
- });
4471
- };
4668
+ /**
4669
+ * Returns the minimum element in an observable sequence according to the optional comparer else a default greater than less than check.
4670
+ * @example
4671
+ * var res = source.min();
4672
+ * var res = source.min(function (x, y) { return x.value - y.value; });
4673
+ * @param {Function} [comparer] Comparer used to compare elements.
4674
+ * @returns {Observable} An observable sequence containing a single element with the minimum element in the source sequence.
4675
+ */
4676
+ observableProto.min = function (comparer) {
4677
+ return this.minBy(identity, comparer).map(function (x) { return firstOnly(x); });
4678
+ };
4472
4679
 
4473
- /**
4474
- * Returns the elements in an observable sequence with the maximum key value according to the specified comparer.
4475
- * @example
4476
- * var res = source.maxBy(function (x) { return x.value; });
4477
- * var res = source.maxBy(function (x) { return x.value; }, function (x, y) { return x - y;; });
4478
- * @param {Function} keySelector Key selector function.
4479
- * @param {Function} [comparer] Comparer used to compare key values.
4480
- * @returns {Observable} An observable sequence containing a list of zero or more elements that have a maximum key value.
4481
- */
4482
- observableProto.maxBy = function (keySelector, comparer) {
4483
- comparer || (comparer = defaultSubComparer);
4484
- return extremaBy(this, keySelector, comparer);
4485
- };
4680
+ /**
4681
+ * Returns the elements in an observable sequence with the maximum key value according to the specified comparer.
4682
+ * @example
4683
+ * var res = source.maxBy(function (x) { return x.value; });
4684
+ * var res = source.maxBy(function (x) { return x.value; }, function (x, y) { return x - y;; });
4685
+ * @param {Function} keySelector Key selector function.
4686
+ * @param {Function} [comparer] Comparer used to compare key values.
4687
+ * @returns {Observable} An observable sequence containing a list of zero or more elements that have a maximum key value.
4688
+ */
4689
+ observableProto.maxBy = function (keySelector, comparer) {
4690
+ comparer || (comparer = defaultSubComparer);
4691
+ return extremaBy(this, keySelector, comparer);
4692
+ };
4486
4693
 
4487
- /**
4488
- * Returns the maximum value in an observable sequence according to the specified comparer.
4489
- * @example
4490
- * var res = source.max();
4491
- * var res = source.max(function (x, y) { return x.value - y.value; });
4492
- * @param {Function} [comparer] Comparer used to compare elements.
4493
- * @returns {Observable} An observable sequence containing a single element with the maximum element in the source sequence.
4494
- */
4495
- observableProto.max = function (comparer) {
4496
- return this.maxBy(identity, comparer).select(function (x) {
4497
- return firstOnly(x);
4498
- });
4499
- };
4694
+ /**
4695
+ * Returns the maximum value in an observable sequence according to the specified comparer.
4696
+ * @example
4697
+ * var res = source.max();
4698
+ * var res = source.max(function (x, y) { return x.value - y.value; });
4699
+ * @param {Function} [comparer] Comparer used to compare elements.
4700
+ * @returns {Observable} An observable sequence containing a single element with the maximum element in the source sequence.
4701
+ */
4702
+ observableProto.max = function (comparer) {
4703
+ return this.maxBy(identity, comparer).map(function (x) { return firstOnly(x); });
4704
+ };
4500
4705
 
4501
4706
  /**
4502
4707
  * Computes the average of an observable sequence of values that are in the sequence or obtained by invoking a transform function on each element of the input sequence if present.
@@ -4520,28 +4725,6 @@ if (!Array.prototype.forEach) {
4520
4725
  });
4521
4726
  };
4522
4727
 
4523
- function sequenceEqualArray(first, second, comparer) {
4524
- return new AnonymousObservable(function (observer) {
4525
- var count = 0, len = second.length;
4526
- return first.subscribe(function (value) {
4527
- var equal = false;
4528
- try {
4529
- count < len && (equal = comparer(value, second[count++]));
4530
- } catch (e) {
4531
- observer.onError(e);
4532
- return;
4533
- }
4534
- if (!equal) {
4535
- observer.onNext(false);
4536
- observer.onCompleted();
4537
- }
4538
- }, observer.onError.bind(observer), function () {
4539
- observer.onNext(count === len);
4540
- observer.onCompleted();
4541
- });
4542
- });
4543
- }
4544
-
4545
4728
  /**
4546
4729
  * Determines whether two sequences are equal by comparing the elements pairwise using a specified equality comparer.
4547
4730
  *
@@ -4557,9 +4740,6 @@ if (!Array.prototype.forEach) {
4557
4740
  observableProto.sequenceEqual = function (second, comparer) {
4558
4741
  var first = this;
4559
4742
  comparer || (comparer = defaultComparer);
4560
- if (Array.isArray(second)) {
4561
- return sequenceEqualArray(first, second, comparer);
4562
- }
4563
4743
  return new AnonymousObservable(function (observer) {
4564
4744
  var donel = false, doner = false, ql = [], qr = [];
4565
4745
  var subscription1 = first.subscribe(function (x) {
@@ -4595,6 +4775,7 @@ if (!Array.prototype.forEach) {
4595
4775
  }
4596
4776
  });
4597
4777
 
4778
+ (isArrayLike(second) || isIterable(second)) && (second = observableFrom(second));
4598
4779
  isPromise(second) && (second = observableFromPromise(second));
4599
4780
  var subscription2 = second.subscribe(function (x) {
4600
4781
  var equal;
@@ -4629,55 +4810,52 @@ if (!Array.prototype.forEach) {
4629
4810
  }
4630
4811
  });
4631
4812
  return new CompositeDisposable(subscription1, subscription2);
4632
- });
4813
+ }, first);
4633
4814
  };
4634
4815
 
4635
- function elementAtOrDefault(source, index, hasDefault, defaultValue) {
4636
- if (index < 0) {
4637
- throw new Error(argumentOutOfRange);
4816
+ function elementAtOrDefault(source, index, hasDefault, defaultValue) {
4817
+ if (index < 0) { throw new Error(argumentOutOfRange); }
4818
+ return new AnonymousObservable(function (observer) {
4819
+ var i = index;
4820
+ return source.subscribe(function (x) {
4821
+ if (i-- === 0) {
4822
+ observer.onNext(x);
4823
+ observer.onCompleted();
4638
4824
  }
4639
- return new AnonymousObservable(function (observer) {
4640
- var i = index;
4641
- return source.subscribe(function (x) {
4642
- if (i === 0) {
4643
- observer.onNext(x);
4644
- observer.onCompleted();
4645
- }
4646
- i--;
4647
- }, observer.onError.bind(observer), function () {
4648
- if (!hasDefault) {
4649
- observer.onError(new Error(argumentOutOfRange));
4650
- } else {
4651
- observer.onNext(defaultValue);
4652
- observer.onCompleted();
4653
- }
4654
- });
4655
- });
4656
- }
4825
+ }, observer.onError.bind(observer), function () {
4826
+ if (!hasDefault) {
4827
+ observer.onError(new Error(argumentOutOfRange));
4828
+ } else {
4829
+ observer.onNext(defaultValue);
4830
+ observer.onCompleted();
4831
+ }
4832
+ });
4833
+ }, source);
4834
+ }
4657
4835
 
4658
- /**
4659
- * Returns the element at a specified index in a sequence.
4660
- * @example
4661
- * var res = source.elementAt(5);
4662
- * @param {Number} index The zero-based index of the element to retrieve.
4663
- * @returns {Observable} An observable sequence that produces the element at the specified position in the source sequence.
4664
- */
4665
- observableProto.elementAt = function (index) {
4666
- return elementAtOrDefault(this, index, false);
4667
- };
4836
+ /**
4837
+ * Returns the element at a specified index in a sequence.
4838
+ * @example
4839
+ * var res = source.elementAt(5);
4840
+ * @param {Number} index The zero-based index of the element to retrieve.
4841
+ * @returns {Observable} An observable sequence that produces the element at the specified position in the source sequence.
4842
+ */
4843
+ observableProto.elementAt = function (index) {
4844
+ return elementAtOrDefault(this, index, false);
4845
+ };
4668
4846
 
4669
- /**
4670
- * Returns the element at a specified index in a sequence or a default value if the index is out of range.
4671
- * @example
4672
- * var res = source.elementAtOrDefault(5);
4673
- * var res = source.elementAtOrDefault(5, 0);
4674
- * @param {Number} index The zero-based index of the element to retrieve.
4675
- * @param [defaultValue] The default value if the index is outside the bounds of the source sequence.
4676
- * @returns {Observable} An observable sequence that produces the element at the specified position in the source sequence, or a default value if the index is outside the bounds of the source sequence.
4677
- */
4678
- observableProto.elementAtOrDefault = function (index, defaultValue) {
4679
- return elementAtOrDefault(this, index, true, defaultValue);
4680
- };
4847
+ /**
4848
+ * Returns the element at a specified index in a sequence or a default value if the index is out of range.
4849
+ * @example
4850
+ * var res = source.elementAtOrDefault(5);
4851
+ * var res = source.elementAtOrDefault(5, 0);
4852
+ * @param {Number} index The zero-based index of the element to retrieve.
4853
+ * @param [defaultValue] The default value if the index is outside the bounds of the source sequence.
4854
+ * @returns {Observable} An observable sequence that produces the element at the specified position in the source sequence, or a default value if the index is outside the bounds of the source sequence.
4855
+ */
4856
+ observableProto.elementAtOrDefault = function (index, defaultValue) {
4857
+ return elementAtOrDefault(this, index, true, defaultValue);
4858
+ };
4681
4859
 
4682
4860
  function singleOrDefaultAsync(source, hasDefault, defaultValue) {
4683
4861
  return new AnonymousObservable(function (observer) {
@@ -4697,14 +4875,11 @@ if (!Array.prototype.forEach) {
4697
4875
  observer.onCompleted();
4698
4876
  }
4699
4877
  });
4700
- });
4878
+ }, source);
4701
4879
  }
4702
4880
 
4703
4881
  /**
4704
4882
  * Returns the only element of an observable sequence that satisfies the condition in the optional predicate, and reports an exception if there is not exactly one element in the observable sequence.
4705
- * @example
4706
- * var res = res = source.single();
4707
- * var res = res = source.single(function (x) { return x === 42; });
4708
4883
  * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4709
4884
  * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4710
4885
  * @returns {Observable} Sequence containing the single element in the observable sequence that satisfies the condition in the predicate.
@@ -4734,211 +4909,198 @@ if (!Array.prototype.forEach) {
4734
4909
  singleOrDefaultAsync(this, true, defaultValue);
4735
4910
  };
4736
4911
 
4737
- function firstOrDefaultAsync(source, hasDefault, defaultValue) {
4738
- return new AnonymousObservable(function (observer) {
4739
- return source.subscribe(function (x) {
4740
- observer.onNext(x);
4741
- observer.onCompleted();
4742
- }, observer.onError.bind(observer), function () {
4743
- if (!hasDefault) {
4744
- observer.onError(new Error(sequenceContainsNoElements));
4745
- } else {
4746
- observer.onNext(defaultValue);
4747
- observer.onCompleted();
4748
- }
4749
- });
4750
- });
4751
- }
4912
+ function firstOrDefaultAsync(source, hasDefault, defaultValue) {
4913
+ return new AnonymousObservable(function (observer) {
4914
+ return source.subscribe(function (x) {
4915
+ observer.onNext(x);
4916
+ observer.onCompleted();
4917
+ }, observer.onError.bind(observer), function () {
4918
+ if (!hasDefault) {
4919
+ observer.onError(new Error(sequenceContainsNoElements));
4920
+ } else {
4921
+ observer.onNext(defaultValue);
4922
+ observer.onCompleted();
4923
+ }
4924
+ });
4925
+ }, source);
4926
+ }
4752
4927
 
4753
- /**
4754
- * Returns the first element of an observable sequence that satisfies the condition in the predicate if present else the first item in the sequence.
4755
- * @example
4756
- * var res = res = source.first();
4757
- * var res = res = source.first(function (x) { return x > 3; });
4758
- * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4759
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4760
- * @returns {Observable} Sequence containing the first element in the observable sequence that satisfies the condition in the predicate if provided, else the first item in the sequence.
4761
- */
4762
- observableProto.first = function (predicate, thisArg) {
4763
- return predicate ?
4764
- this.where(predicate, thisArg).first() :
4765
- firstOrDefaultAsync(this, false);
4766
- };
4928
+ /**
4929
+ * Returns the first element of an observable sequence that satisfies the condition in the predicate if present else the first item in the sequence.
4930
+ * @example
4931
+ * var res = res = source.first();
4932
+ * var res = res = source.first(function (x) { return x > 3; });
4933
+ * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4934
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4935
+ * @returns {Observable} Sequence containing the first element in the observable sequence that satisfies the condition in the predicate if provided, else the first item in the sequence.
4936
+ */
4937
+ observableProto.first = function (predicate, thisArg) {
4938
+ return predicate ?
4939
+ this.where(predicate, thisArg).first() :
4940
+ firstOrDefaultAsync(this, false);
4941
+ };
4767
4942
 
4768
- /**
4769
- * Returns the first element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
4770
- * @example
4771
- * var res = res = source.firstOrDefault();
4772
- * var res = res = source.firstOrDefault(function (x) { return x > 3; });
4773
- * var res = source.firstOrDefault(function (x) { return x > 3; }, 0);
4774
- * var res = source.firstOrDefault(null, 0);
4775
- * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4776
- * @param {Any} [defaultValue] The default value if no such element exists. If not specified, defaults to null.
4777
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4778
- * @returns {Observable} Sequence containing the first element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
4779
- */
4780
- observableProto.firstOrDefault = function (predicate, defaultValue, thisArg) {
4781
- return predicate ?
4782
- this.where(predicate).firstOrDefault(null, defaultValue) :
4783
- firstOrDefaultAsync(this, true, defaultValue);
4784
- };
4943
+ /**
4944
+ * Returns the first element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
4945
+ * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4946
+ * @param {Any} [defaultValue] The default value if no such element exists. If not specified, defaults to null.
4947
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4948
+ * @returns {Observable} Sequence containing the first element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
4949
+ */
4950
+ observableProto.firstOrDefault = function (predicate, defaultValue, thisArg) {
4951
+ return predicate ?
4952
+ this.where(predicate).firstOrDefault(null, defaultValue) :
4953
+ firstOrDefaultAsync(this, true, defaultValue);
4954
+ };
4785
4955
 
4786
- function lastOrDefaultAsync(source, hasDefault, defaultValue) {
4787
- return new AnonymousObservable(function (observer) {
4788
- var value = defaultValue, seenValue = false;
4789
- return source.subscribe(function (x) {
4790
- value = x;
4791
- seenValue = true;
4792
- }, observer.onError.bind(observer), function () {
4793
- if (!seenValue && !hasDefault) {
4794
- observer.onError(new Error(sequenceContainsNoElements));
4795
- } else {
4796
- observer.onNext(value);
4797
- observer.onCompleted();
4798
- }
4799
- });
4800
- });
4801
- }
4956
+ function lastOrDefaultAsync(source, hasDefault, defaultValue) {
4957
+ return new AnonymousObservable(function (observer) {
4958
+ var value = defaultValue, seenValue = false;
4959
+ return source.subscribe(function (x) {
4960
+ value = x;
4961
+ seenValue = true;
4962
+ }, observer.onError.bind(observer), function () {
4963
+ if (!seenValue && !hasDefault) {
4964
+ observer.onError(new Error(sequenceContainsNoElements));
4965
+ } else {
4966
+ observer.onNext(value);
4967
+ observer.onCompleted();
4968
+ }
4969
+ });
4970
+ }, source);
4971
+ }
4802
4972
 
4803
- /**
4804
- * Returns the last element of an observable sequence that satisfies the condition in the predicate if specified, else the last element.
4805
- * @example
4806
- * var res = source.last();
4807
- * var res = source.last(function (x) { return x > 3; });
4808
- * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4809
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4810
- * @returns {Observable} Sequence containing the last element in the observable sequence that satisfies the condition in the predicate.
4811
- */
4812
- observableProto.last = function (predicate, thisArg) {
4813
- return predicate ?
4814
- this.where(predicate, thisArg).last() :
4815
- lastOrDefaultAsync(this, false);
4816
- };
4973
+ /**
4974
+ * Returns the last element of an observable sequence that satisfies the condition in the predicate if specified, else the last element.
4975
+ * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4976
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4977
+ * @returns {Observable} Sequence containing the last element in the observable sequence that satisfies the condition in the predicate.
4978
+ */
4979
+ observableProto.last = function (predicate, thisArg) {
4980
+ return predicate ?
4981
+ this.where(predicate, thisArg).last() :
4982
+ lastOrDefaultAsync(this, false);
4983
+ };
4817
4984
 
4818
- /**
4819
- * Returns the last element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
4820
- * @example
4821
- * var res = source.lastOrDefault();
4822
- * var res = source.lastOrDefault(function (x) { return x > 3; });
4823
- * var res = source.lastOrDefault(function (x) { return x > 3; }, 0);
4824
- * var res = source.lastOrDefault(null, 0);
4825
- * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4826
- * @param [defaultValue] The default value if no such element exists. If not specified, defaults to null.
4827
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4828
- * @returns {Observable} Sequence containing the last element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
4829
- */
4830
- observableProto.lastOrDefault = function (predicate, defaultValue, thisArg) {
4831
- return predicate ?
4832
- this.where(predicate, thisArg).lastOrDefault(null, defaultValue) :
4833
- lastOrDefaultAsync(this, true, defaultValue);
4834
- };
4985
+ /**
4986
+ * Returns the last element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
4987
+ * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
4988
+ * @param [defaultValue] The default value if no such element exists. If not specified, defaults to null.
4989
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4990
+ * @returns {Observable} Sequence containing the last element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
4991
+ */
4992
+ observableProto.lastOrDefault = function (predicate, defaultValue, thisArg) {
4993
+ return predicate ?
4994
+ this.where(predicate, thisArg).lastOrDefault(null, defaultValue) :
4995
+ lastOrDefaultAsync(this, true, defaultValue);
4996
+ };
4835
4997
 
4836
- function findValue (source, predicate, thisArg, yieldIndex) {
4837
- return new AnonymousObservable(function (observer) {
4838
- var i = 0;
4839
- return source.subscribe(function (x) {
4840
- var shouldRun;
4841
- try {
4842
- shouldRun = predicate.call(thisArg, x, i, source);
4843
- } catch(e) {
4844
- observer.onError(e);
4845
- return;
4846
- }
4847
- if (shouldRun) {
4848
- observer.onNext(yieldIndex ? i : x);
4849
- observer.onCompleted();
4850
- } else {
4851
- i++;
4852
- }
4853
- }, observer.onError.bind(observer), function () {
4854
- observer.onNext(yieldIndex ? -1 : undefined);
4855
- observer.onCompleted();
4856
- });
4857
- });
4858
- }
4998
+ function findValue (source, predicate, thisArg, yieldIndex) {
4999
+ return new AnonymousObservable(function (observer) {
5000
+ var i = 0;
5001
+ return source.subscribe(function (x) {
5002
+ var shouldRun;
5003
+ try {
5004
+ shouldRun = predicate.call(thisArg, x, i, source);
5005
+ } catch (e) {
5006
+ observer.onError(e);
5007
+ return;
5008
+ }
5009
+ if (shouldRun) {
5010
+ observer.onNext(yieldIndex ? i : x);
5011
+ observer.onCompleted();
5012
+ } else {
5013
+ i++;
5014
+ }
5015
+ }, observer.onError.bind(observer), function () {
5016
+ observer.onNext(yieldIndex ? -1 : undefined);
5017
+ observer.onCompleted();
5018
+ });
5019
+ }, source);
5020
+ }
4859
5021
 
4860
- /**
4861
- * Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire Observable sequence.
4862
- * @param {Function} predicate The predicate that defines the conditions of the element to search for.
4863
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4864
- * @returns {Observable} An Observable sequence with the first element that matches the conditions defined by the specified predicate, if found; otherwise, undefined.
4865
- */
4866
- observableProto.find = function (predicate, thisArg) {
4867
- return findValue(this, predicate, thisArg, false);
4868
- };
5022
+ /**
5023
+ * Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire Observable sequence.
5024
+ * @param {Function} predicate The predicate that defines the conditions of the element to search for.
5025
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
5026
+ * @returns {Observable} An Observable sequence with the first element that matches the conditions defined by the specified predicate, if found; otherwise, undefined.
5027
+ */
5028
+ observableProto.find = function (predicate, thisArg) {
5029
+ return findValue(this, predicate, thisArg, false);
5030
+ };
5031
+
5032
+ /**
5033
+ * Searches for an element that matches the conditions defined by the specified predicate, and returns
5034
+ * an Observable sequence with the zero-based index of the first occurrence within the entire Observable sequence.
5035
+ * @param {Function} predicate The predicate that defines the conditions of the element to search for.
5036
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
5037
+ * @returns {Observable} An Observable sequence with the zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, –1.
5038
+ */
5039
+ observableProto.findIndex = function (predicate, thisArg) {
5040
+ return findValue(this, predicate, thisArg, true);
5041
+ };
5042
+
5043
+
5044
+ /**
5045
+ * Converts the observable sequence to a Set if it exists.
5046
+ * @returns {Observable} An observable sequence with a single value of a Set containing the values from the observable sequence.
5047
+ */
5048
+ observableProto.toSet = function () {
5049
+ if (typeof root.Set === 'undefined') { throw new TypeError(); }
5050
+ var source = this;
5051
+ return new AnonymousObservable(function (observer) {
5052
+ var s = new root.Set();
5053
+ return source.subscribe(
5054
+ s.add.bind(s),
5055
+ observer.onError.bind(observer),
5056
+ function () {
5057
+ observer.onNext(s);
5058
+ observer.onCompleted();
5059
+ });
5060
+ }, source);
5061
+ };
4869
5062
 
4870
- /**
4871
- * Searches for an element that matches the conditions defined by the specified predicate, and returns
4872
- * an Observable sequence with the zero-based index of the first occurrence within the entire Observable sequence.
4873
- * @param {Function} predicate The predicate that defines the conditions of the element to search for.
4874
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
4875
- * @returns {Observable} An Observable sequence with the zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, –1.
4876
- */
4877
- observableProto.findIndex = function (predicate, thisArg) {
4878
- return findValue(this, predicate, thisArg, true);
4879
- };
4880
5063
 
4881
- if (!!root.Set) {
4882
- /**
4883
- * Converts the observable sequence to a Set if it exists.
4884
- * @returns {Observable} An observable sequence with a single value of a Set containing the values from the observable sequence.
4885
- */
4886
- observableProto.toSet = function () {
4887
- var source = this;
4888
- return new AnonymousObservable(function (observer) {
4889
- var s = new root.Set();
4890
- return source.subscribe(
4891
- s.add.bind(s),
4892
- observer.onError.bind(observer),
4893
- function () {
4894
- observer.onNext(s);
4895
- observer.onCompleted();
4896
- });
4897
- });
4898
- };
4899
- }
5064
+ /**
5065
+ * Converts the observable sequence to a Map if it exists.
5066
+ * @param {Function} keySelector A function which produces the key for the Map.
5067
+ * @param {Function} [elementSelector] An optional function which produces the element for the Map. If not present, defaults to the value from the observable sequence.
5068
+ * @returns {Observable} An observable sequence with a single value of a Map containing the values from the observable sequence.
5069
+ */
5070
+ observableProto.toMap = function (keySelector, elementSelector) {
5071
+ if (typeof root.Map === 'undefined') { throw new TypeError(); }
5072
+ var source = this;
5073
+ return new AnonymousObservable(function (observer) {
5074
+ var m = new root.Map();
5075
+ return source.subscribe(
5076
+ function (x) {
5077
+ var key;
5078
+ try {
5079
+ key = keySelector(x);
5080
+ } catch (e) {
5081
+ observer.onError(e);
5082
+ return;
5083
+ }
4900
5084
 
4901
- if (!!root.Map) {
4902
- /**
4903
- * Converts the observable sequence to a Map if it exists.
4904
- * @param {Function} keySelector A function which produces the key for the Map.
4905
- * @param {Function} [elementSelector] An optional function which produces the element for the Map. If not present, defaults to the value from the observable sequence.
4906
- * @returns {Observable} An observable sequence with a single value of a Map containing the values from the observable sequence.
4907
- */
4908
- observableProto.toMap = function (keySelector, elementSelector) {
4909
- var source = this;
4910
- return new AnonymousObservable(function (observer) {
4911
- var m = new root.Map();
4912
- return source.subscribe(
4913
- function (x) {
4914
- var key;
5085
+ var element = x;
5086
+ if (elementSelector) {
4915
5087
  try {
4916
- key = keySelector(x);
5088
+ element = elementSelector(x);
4917
5089
  } catch (e) {
4918
5090
  observer.onError(e);
4919
5091
  return;
4920
5092
  }
5093
+ }
4921
5094
 
4922
- var element = x;
4923
- if (elementSelector) {
4924
- try {
4925
- element = elementSelector(x);
4926
- } catch (e) {
4927
- observer.onError(e);
4928
- return;
4929
- }
4930
- }
4931
-
4932
- m.set(key, element);
4933
- },
4934
- observer.onError.bind(observer),
4935
- function () {
4936
- observer.onNext(m);
4937
- observer.onCompleted();
4938
- });
4939
- });
4940
- };
4941
- }
5095
+ m.set(key, element);
5096
+ },
5097
+ observer.onError.bind(observer),
5098
+ function () {
5099
+ observer.onNext(m);
5100
+ observer.onCompleted();
5101
+ });
5102
+ }, source);
5103
+ };
4942
5104
 
4943
5105
  var fnString = 'function',
4944
5106
  throwString = 'throw';
@@ -4983,7 +5145,7 @@ if (!Array.prototype.forEach) {
4983
5145
  return --pending || done(null, results);
4984
5146
  }
4985
5147
 
4986
- fn.call(ctx, function(err, res){
5148
+ fn.call(ctx, function(err, res) {
4987
5149
  if (finished) { return; }
4988
5150
 
4989
5151
  if (err) {
@@ -5018,7 +5180,7 @@ if (!Array.prototype.forEach) {
5018
5180
  }
5019
5181
 
5020
5182
  function promiseToThunk(promise) {
5021
- return function(fn){
5183
+ return function(fn) {
5022
5184
  promise.then(function(res) {
5023
5185
  fn(null, res);
5024
5186
  }, fn);
@@ -5074,7 +5236,9 @@ if (!Array.prototype.forEach) {
5074
5236
  var ret;
5075
5237
 
5076
5238
  // multiple args
5077
- if (arguments.length > 2) res = slice.call(arguments, 1);
5239
+ if (arguments.length > 2) {
5240
+ res = slice.call(arguments, 1);
5241
+ }
5078
5242
 
5079
5243
  if (err) {
5080
5244
  try {
@@ -5101,7 +5265,7 @@ if (!Array.prototype.forEach) {
5101
5265
  if (typeof ret.value === fnString) {
5102
5266
  var called = false;
5103
5267
  try {
5104
- ret.value.call(ctx, function(){
5268
+ ret.value.call(ctx, function() {
5105
5269
  if (called) {
5106
5270
  return;
5107
5271
  }
@@ -5134,13 +5298,13 @@ if (!Array.prototype.forEach) {
5134
5298
  * @returns {Function} A function, when executed will continue the state machine.
5135
5299
  */
5136
5300
  Rx.denodify = function (fn) {
5137
- return function (){
5301
+ return function () {
5138
5302
  var args = slice.call(arguments),
5139
5303
  results,
5140
5304
  called,
5141
5305
  callback;
5142
5306
 
5143
- args.push(function(){
5307
+ args.push(function() {
5144
5308
  results = arguments;
5145
5309
 
5146
5310
  if (callback && !called) {
@@ -5151,7 +5315,7 @@ if (!Array.prototype.forEach) {
5151
5315
 
5152
5316
  fn.apply(this, args);
5153
5317
 
5154
- return function (fn){
5318
+ return function (fn) {
5155
5319
  callback = fn;
5156
5320
 
5157
5321
  if (results && !called) {
@@ -5164,7 +5328,7 @@ if (!Array.prototype.forEach) {
5164
5328
 
5165
5329
  function error(err) {
5166
5330
  if (!err) { return; }
5167
- timeoutScheduler.schedule(function(){
5331
+ timeoutScheduler.schedule(function() {
5168
5332
  throw err;
5169
5333
  });
5170
5334
  }
@@ -5192,12 +5356,6 @@ if (!Array.prototype.forEach) {
5192
5356
 
5193
5357
  /**
5194
5358
  * Converts the function into an asynchronous function. Each invocation of the resulting asynchronous function causes an invocation of the original synchronous function on the specified scheduler.
5195
- *
5196
- * @example
5197
- * var res = Rx.Observable.toAsync(function (x, y) { return x + y; })(4, 3);
5198
- * var res = Rx.Observable.toAsync(function (x, y) { return x + y; }, Rx.Scheduler.timeout)(4, 3);
5199
- * var res = Rx.Observable.toAsync(function (x) { this.log(x); }, Rx.Scheduler.timeout, console)('hello');
5200
- *
5201
5359
  * @param {Function} function Function to convert to an asynchronous function.
5202
5360
  * @param {Scheduler} [scheduler] Scheduler to run the function on. If not specified, defaults to Scheduler.timeout.
5203
5361
  * @param {Mixed} [context] The context for the func parameter to be executed. If not specified, defaults to undefined.
@@ -5237,12 +5395,12 @@ if (!Array.prototype.forEach) {
5237
5395
  var args = slice.call(arguments, 0);
5238
5396
 
5239
5397
  return new AnonymousObservable(function (observer) {
5240
- function handler(e) {
5241
- var results = e;
5398
+ function handler() {
5399
+ var results = arguments;
5242
5400
 
5243
5401
  if (selector) {
5244
5402
  try {
5245
- results = selector(arguments);
5403
+ results = selector(results);
5246
5404
  } catch (err) {
5247
5405
  observer.onError(err);
5248
5406
  return;
@@ -5339,12 +5497,12 @@ if (!Array.prototype.forEach) {
5339
5497
  event.relatedTarget = event.toElement;
5340
5498
  }
5341
5499
  // Adding stopPropogation and preventDefault to IE
5342
- if (!event.stopPropagation){
5500
+ if (!event.stopPropagation) {
5343
5501
  event.stopPropagation = stopPropagation;
5344
5502
  event.preventDefault = preventDefault;
5345
5503
  }
5346
5504
  // Normalize key events
5347
- switch(event.type){
5505
+ switch (event.type) {
5348
5506
  case 'keypress':
5349
5507
  var c = ('charCode' in event ? event.charCode : event.keyCode);
5350
5508
  if (c == 10) {
@@ -5591,17 +5749,22 @@ if (!Array.prototype.forEach) {
5591
5749
 
5592
5750
  function combineLatestSource(source, subject, resultSelector) {
5593
5751
  return new AnonymousObservable(function (observer) {
5594
- var n = 2,
5595
- hasValue = [false, false],
5752
+ var hasValue = [false, false],
5596
5753
  hasValueAll = false,
5597
5754
  isDone = false,
5598
- values = new Array(n);
5755
+ values = new Array(2),
5756
+ err;
5599
5757
 
5600
5758
  function next(x, i) {
5601
5759
  values[i] = x
5602
5760
  var res;
5603
5761
  hasValue[i] = true;
5604
5762
  if (hasValueAll || (hasValueAll = hasValue.every(identity))) {
5763
+ if (err) {
5764
+ observer.onError(err);
5765
+ return;
5766
+ }
5767
+
5605
5768
  try {
5606
5769
  res = resultSelector.apply(null, values);
5607
5770
  } catch (ex) {
@@ -5609,7 +5772,8 @@ if (!Array.prototype.forEach) {
5609
5772
  return;
5610
5773
  }
5611
5774
  observer.onNext(res);
5612
- } else if (isDone) {
5775
+ }
5776
+ if (isDone && values[1]) {
5613
5777
  observer.onCompleted();
5614
5778
  }
5615
5779
  }
@@ -5619,23 +5783,33 @@ if (!Array.prototype.forEach) {
5619
5783
  function (x) {
5620
5784
  next(x, 0);
5621
5785
  },
5622
- observer.onError.bind(observer),
5786
+ function (e) {
5787
+ if (values[1]) {
5788
+ observer.onError(e);
5789
+ } else {
5790
+ err = e;
5791
+ }
5792
+ },
5623
5793
  function () {
5624
5794
  isDone = true;
5625
- observer.onCompleted();
5795
+ values[1] && observer.onCompleted();
5626
5796
  }),
5627
5797
  subject.subscribe(
5628
5798
  function (x) {
5629
5799
  next(x, 1);
5630
5800
  },
5631
- observer.onError.bind(observer))
5801
+ observer.onError.bind(observer),
5802
+ function () {
5803
+ isDone = true;
5804
+ next(true, 1);
5805
+ })
5632
5806
  );
5633
5807
  });
5634
5808
  }
5635
5809
 
5636
- var PausableBufferedObservable = (function (_super) {
5810
+ var PausableBufferedObservable = (function (__super__) {
5637
5811
 
5638
- inherits(PausableBufferedObservable, _super);
5812
+ inherits(PausableBufferedObservable, __super__);
5639
5813
 
5640
5814
  function subscribe(observer) {
5641
5815
  var q = [], previousShouldFire;
@@ -5695,7 +5869,7 @@ if (!Array.prototype.forEach) {
5695
5869
  this.pauser = this.controller;
5696
5870
  }
5697
5871
 
5698
- _super.call(this, subscribe);
5872
+ __super__.call(this, subscribe);
5699
5873
  }
5700
5874
 
5701
5875
  PausableBufferedObservable.prototype.pause = function () {
@@ -5909,7 +6083,7 @@ if (!Array.prototype.forEach) {
5909
6083
  new AnonymousObservable(function (observer) {
5910
6084
  var connectable = source.multicast(subjectOrSubjectSelector());
5911
6085
  return new CompositeDisposable(selector(connectable).subscribe(observer), connectable.connect());
5912
- }) :
6086
+ }, source) :
5913
6087
  new ConnectableObservable(source, subjectOrSubjectSelector);
5914
6088
  };
5915
6089
 
@@ -5933,10 +6107,6 @@ if (!Array.prototype.forEach) {
5933
6107
  /**
5934
6108
  * Returns an observable sequence that shares a single subscription to the underlying sequence.
5935
6109
  * This operator is a specialization of publish which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
5936
- *
5937
- * @example
5938
- * var res = source.share();
5939
- *
5940
6110
  * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
5941
6111
  */
5942
6112
  observableProto.share = function () {
@@ -5983,10 +6153,6 @@ if (!Array.prototype.forEach) {
5983
6153
  /**
5984
6154
  * Returns an observable sequence that shares a single subscription to the underlying sequence and starts with an initialValue.
5985
6155
  * This operator is a specialization of publishValue which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
5986
- *
5987
- * @example
5988
- * var res = source.shareValue(42);
5989
- *
5990
6156
  * @param {Mixed} initialValue Initial value received by observers upon subscription.
5991
6157
  * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
5992
6158
  */
@@ -6173,21 +6339,17 @@ if (!Array.prototype.forEach) {
6173
6339
  this._trim(this.scheduler.now());
6174
6340
  this.observers.push(so);
6175
6341
 
6176
- var n = this.q.length;
6177
-
6178
6342
  for (var i = 0, len = this.q.length; i < len; i++) {
6179
6343
  so.onNext(this.q[i].value);
6180
6344
  }
6181
6345
 
6182
6346
  if (this.hasError) {
6183
- n++;
6184
6347
  so.onError(this.error);
6185
6348
  } else if (this.isStopped) {
6186
- n++;
6187
6349
  so.onCompleted();
6188
6350
  }
6189
6351
 
6190
- so.ensureActive(n);
6352
+ so.ensureActive();
6191
6353
  return subscription;
6192
6354
  }
6193
6355
 
@@ -6339,7 +6501,7 @@ if (!Array.prototype.forEach) {
6339
6501
  duplicatekey = "duplicate key";
6340
6502
 
6341
6503
  function isPrime(candidate) {
6342
- if (candidate & 1 === 0) { return candidate === 2; }
6504
+ if ((candidate & 1) === 0) { return candidate === 2; }
6343
6505
  var num1 = Math.sqrt(candidate),
6344
6506
  num2 = 3;
6345
6507
  while (num2 <= num1) {
@@ -6368,7 +6530,7 @@ if (!Array.prototype.forEach) {
6368
6530
  if (!str.length) { return hash; }
6369
6531
  for (var i = 0, len = str.length; i < len; i++) {
6370
6532
  var character = str.charCodeAt(i);
6371
- hash = ((hash<<5)-hash)+character;
6533
+ hash = ((hash << 5) - hash) + character;
6372
6534
  hash = hash & hash;
6373
6535
  }
6374
6536
  return hash;
@@ -6402,10 +6564,10 @@ if (!Array.prototype.forEach) {
6402
6564
  if (typeof valueOf === 'number') { return numberHashFn(valueOf); }
6403
6565
  if (typeof obj === 'string') { return stringHashFn(valueOf); }
6404
6566
  }
6405
- if (obj.getHashCode) { return obj.getHashCode(); }
6567
+ if (obj.hashCode) { return obj.hashCode(); }
6406
6568
 
6407
6569
  var id = 17 * uniqueIdCounter++;
6408
- obj.getHashCode = function () { return id; };
6570
+ obj.hashCode = function () { return id; };
6409
6571
  return id;
6410
6572
  };
6411
6573
  }());
@@ -6438,7 +6600,7 @@ if (!Array.prototype.forEach) {
6438
6600
  };
6439
6601
 
6440
6602
  dictionaryProto.add = function (key, value) {
6441
- return this._insert(key, value, true);
6603
+ this._insert(key, value, true);
6442
6604
  };
6443
6605
 
6444
6606
  dictionaryProto._insert = function (key, value, add) {
@@ -6666,7 +6828,7 @@ if (!Array.prototype.forEach) {
6666
6828
  var result;
6667
6829
  try {
6668
6830
  result = resultSelector(v, value);
6669
- } catch(exn) {
6831
+ } catch (exn) {
6670
6832
  observer.onError(exn);
6671
6833
  return;
6672
6834
  }
@@ -6681,7 +6843,7 @@ if (!Array.prototype.forEach) {
6681
6843
  })
6682
6844
  );
6683
6845
  return group;
6684
- });
6846
+ }, left);
6685
6847
  };
6686
6848
 
6687
6849
  /**
@@ -6793,7 +6955,7 @@ if (!Array.prototype.forEach) {
6793
6955
  );
6794
6956
 
6795
6957
  return r;
6796
- });
6958
+ }, left);
6797
6959
  };
6798
6960
 
6799
6961
  /**
@@ -6863,7 +7025,7 @@ if (!Array.prototype.forEach) {
6863
7025
  }));
6864
7026
 
6865
7027
  return r;
6866
- });
7028
+ }, source);
6867
7029
  }
6868
7030
 
6869
7031
  function observableWindowWithClosingSelector(windowClosingSelector) {
@@ -6883,7 +7045,7 @@ if (!Array.prototype.forEach) {
6883
7045
  win.onCompleted();
6884
7046
  observer.onCompleted();
6885
7047
  }));
6886
-
7048
+
6887
7049
  function createWindowClose () {
6888
7050
  var windowClose;
6889
7051
  try {
@@ -6910,7 +7072,7 @@ if (!Array.prototype.forEach) {
6910
7072
 
6911
7073
  createWindowClose();
6912
7074
  return r;
6913
- });
7075
+ }, source);
6914
7076
  }
6915
7077
 
6916
7078
  /**
@@ -6934,7 +7096,7 @@ if (!Array.prototype.forEach) {
6934
7096
  },
6935
7097
  observer.onError.bind(observer),
6936
7098
  observer.onCompleted.bind(observer));
6937
- });
7099
+ }, source);
6938
7100
  };
6939
7101
 
6940
7102
  /**
@@ -6968,16 +7130,16 @@ if (!Array.prototype.forEach) {
6968
7130
  });
6969
7131
  }
6970
7132
 
6971
- /**
6972
- * Returns an observable sequence that is the result of invoking the selector on the source sequence, without sharing subscriptions.
6973
- * This operator allows for a fluent style of writing queries that use the same sequence multiple times.
6974
- *
6975
- * @param {Function} selector Selector function which can use the source sequence as many times as needed, without sharing subscriptions to the source sequence.
6976
- * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
6977
- */
6978
- observableProto.letBind = observableProto['let'] = function (func) {
6979
- return func(this);
6980
- };
7133
+ /**
7134
+ * Returns an observable sequence that is the result of invoking the selector on the source sequence, without sharing subscriptions.
7135
+ * This operator allows for a fluent style of writing queries that use the same sequence multiple times.
7136
+ *
7137
+ * @param {Function} selector Selector function which can use the source sequence as many times as needed, without sharing subscriptions to the source sequence.
7138
+ * @returns {Observable} An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
7139
+ */
7140
+ observableProto.letBind = observableProto['let'] = function (func) {
7141
+ return func(this);
7142
+ };
6981
7143
 
6982
7144
  /**
6983
7145
  * Determines whether an observable collection contains values. There is an alias for this method called 'ifThen' for browsers <IE9
@@ -7028,16 +7190,16 @@ if (!Array.prototype.forEach) {
7028
7190
  return enumerableWhile(condition, source).concat();
7029
7191
  };
7030
7192
 
7031
- /**
7032
- * Repeats source as long as condition holds emulating a do while loop.
7033
- *
7034
- * @param {Function} condition The condition which determines if the source will be repeated.
7035
- * @param {Observable} source The observable sequence that will be run if the condition function returns true.
7036
- * @returns {Observable} An observable sequence which is repeated as long as the condition holds.
7037
- */
7038
- observableProto.doWhile = function (condition) {
7039
- return observableConcat([this, observableWhileDo(condition, this)]);
7040
- };
7193
+ /**
7194
+ * Repeats source as long as condition holds emulating a do while loop.
7195
+ *
7196
+ * @param {Function} condition The condition which determines if the source will be repeated.
7197
+ * @param {Observable} source The observable sequence that will be run if the condition function returns true.
7198
+ * @returns {Observable} An observable sequence which is repeated as long as the condition holds.
7199
+ */
7200
+ observableProto.doWhile = function (condition) {
7201
+ return observableConcat([this, observableWhileDo(condition, this)]);
7202
+ };
7041
7203
 
7042
7204
  /**
7043
7205
  * Uses selector to determine which source in sources to use.
@@ -7088,8 +7250,8 @@ if (!Array.prototype.forEach) {
7088
7250
  var ensureActive = function () {
7089
7251
  var isOwner = false;
7090
7252
  if (q.length > 0) {
7091
- isOwner = !isAcquired;
7092
- isAcquired = true;
7253
+ isOwner = !isAcquired;
7254
+ isAcquired = true;
7093
7255
  }
7094
7256
  if (isOwner) {
7095
7257
  m.setDisposable(scheduler.scheduleRecursive(function (self) {
@@ -7129,7 +7291,7 @@ if (!Array.prototype.forEach) {
7129
7291
  activeCount++;
7130
7292
  ensureActive();
7131
7293
  return d;
7132
- });
7294
+ }, this);
7133
7295
  };
7134
7296
 
7135
7297
  /**
@@ -7270,7 +7432,7 @@ if (!Array.prototype.forEach) {
7270
7432
  );
7271
7433
 
7272
7434
  return new CompositeDisposable(leftSubscription, rightSubscription);
7273
- });
7435
+ }, first);
7274
7436
  };
7275
7437
 
7276
7438
  /**
@@ -7301,7 +7463,7 @@ if (!Array.prototype.forEach) {
7301
7463
  )
7302
7464
  .observeOn(scheduler)
7303
7465
  .map(selector);
7304
- });
7466
+ }, source);
7305
7467
  };
7306
7468
 
7307
7469
  var ChainObservable = (function (__super__) {
@@ -7310,7 +7472,7 @@ if (!Array.prototype.forEach) {
7310
7472
  var self = this, g = new CompositeDisposable();
7311
7473
  g.add(currentThreadScheduler.schedule(function () {
7312
7474
  observer.onNext(self.head);
7313
- g.add(self.tail.mergeObservable().subscribe(observer));
7475
+ g.add(self.tail.mergeAll().subscribe(observer));
7314
7476
  }));
7315
7477
 
7316
7478
  return g;
@@ -7746,7 +7908,7 @@ if (!Array.prototype.forEach) {
7746
7908
  }
7747
7909
  });
7748
7910
  return new CompositeDisposable(subscription, cancelable);
7749
- });
7911
+ }, source);
7750
7912
  }
7751
7913
 
7752
7914
  function observableDelayDate(source, dueTime, scheduler) {
@@ -7778,16 +7940,11 @@ if (!Array.prototype.forEach) {
7778
7940
 
7779
7941
  /**
7780
7942
  * Ignores values from an observable sequence which are followed by another value before dueTime.
7781
- *
7782
- * @example
7783
- * 1 - res = source.throttle(5000); // 5 seconds
7784
- * 2 - res = source.throttle(5000, scheduler);
7785
- *
7786
- * @param {Number} dueTime Duration of the throttle period for each value (specified as an integer denoting milliseconds).
7787
- * @param {Scheduler} [scheduler] Scheduler to run the throttle timers on. If not specified, the timeout scheduler is used.
7788
- * @returns {Observable} The throttled sequence.
7943
+ * @param {Number} dueTime Duration of the debounce period for each value (specified as an integer denoting milliseconds).
7944
+ * @param {Scheduler} [scheduler] Scheduler to run the debounce timers on. If not specified, the timeout scheduler is used.
7945
+ * @returns {Observable} The debounced sequence.
7789
7946
  */
7790
- observableProto.throttle = function (dueTime, scheduler) {
7947
+ observableProto.debounce = observableProto.throttleWithTimeout = function (dueTime, scheduler) {
7791
7948
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
7792
7949
  var source = this;
7793
7950
  return new AnonymousObservable(function (observer) {
@@ -7819,7 +7976,15 @@ if (!Array.prototype.forEach) {
7819
7976
  id++;
7820
7977
  });
7821
7978
  return new CompositeDisposable(subscription, cancelable);
7822
- });
7979
+ }, this);
7980
+ };
7981
+
7982
+ /**
7983
+ * @deprecated use #debounce or #throttleWithTimeout instead.
7984
+ */
7985
+ observableProto.throttle = function(dueTime, scheduler) {
7986
+ deprecate('throttle', 'debounce or throttleWithTimeout');
7987
+ return this.debounce(dueTime, scheduler);
7823
7988
  };
7824
7989
 
7825
7990
  /**
@@ -7888,18 +8053,18 @@ if (!Array.prototype.forEach) {
7888
8053
  groupDisposable.add(source.subscribe(
7889
8054
  function (x) {
7890
8055
  for (var i = 0, len = q.length; i < len; i++) { q[i].onNext(x); }
7891
- },
8056
+ },
7892
8057
  function (e) {
7893
8058
  for (var i = 0, len = q.length; i < len; i++) { q[i].onError(e); }
7894
8059
  observer.onError(e);
7895
- },
8060
+ },
7896
8061
  function () {
7897
8062
  for (var i = 0, len = q.length; i < len; i++) { q[i].onCompleted(); }
7898
8063
  observer.onCompleted();
7899
8064
  }
7900
8065
  ));
7901
8066
  return refCountDisposable;
7902
- });
8067
+ }, source);
7903
8068
  };
7904
8069
 
7905
8070
  /**
@@ -7933,7 +8098,7 @@ if (!Array.prototype.forEach) {
7933
8098
  createTimer(newId);
7934
8099
  }));
7935
8100
  }
7936
-
8101
+
7937
8102
  observer.onNext(addRef(s, refCountDisposable));
7938
8103
  createTimer(0);
7939
8104
 
@@ -7950,7 +8115,7 @@ if (!Array.prototype.forEach) {
7950
8115
  observer.onNext(addRef(s, refCountDisposable));
7951
8116
  }
7952
8117
  newWindow && createTimer(newId);
7953
- },
8118
+ },
7954
8119
  function (e) {
7955
8120
  s.onError(e);
7956
8121
  observer.onError(e);
@@ -7960,7 +8125,7 @@ if (!Array.prototype.forEach) {
7960
8125
  }
7961
8126
  ));
7962
8127
  return refCountDisposable;
7963
- });
8128
+ }, source);
7964
8129
  };
7965
8130
 
7966
8131
  /**
@@ -8038,7 +8203,6 @@ if (!Array.prototype.forEach) {
8038
8203
  };
8039
8204
 
8040
8205
  function sampleObservable(source, sampler) {
8041
-
8042
8206
  return new AnonymousObservable(function (observer) {
8043
8207
  var atEnd, value, hasValue;
8044
8208
 
@@ -8059,7 +8223,7 @@ if (!Array.prototype.forEach) {
8059
8223
  }),
8060
8224
  sampler.subscribe(sampleSubscribe, observer.onError.bind(observer), sampleSubscribe)
8061
8225
  );
8062
- });
8226
+ }, source);
8063
8227
  }
8064
8228
 
8065
8229
  /**
@@ -8074,7 +8238,7 @@ if (!Array.prototype.forEach) {
8074
8238
  * @param {Scheduler} [scheduler] Scheduler to run the sampling timer on. If not specified, the timeout scheduler is used.
8075
8239
  * @returns {Observable} Sampled observable sequence.
8076
8240
  */
8077
- observableProto.sample = function (intervalOrSampler, scheduler) {
8241
+ observableProto.sample = observableProto.throttleLatest = function (intervalOrSampler, scheduler) {
8078
8242
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
8079
8243
  return typeof intervalOrSampler === 'number' ?
8080
8244
  sampleObservable(this, observableinterval(intervalOrSampler, scheduler)) :
@@ -8135,7 +8299,7 @@ if (!Array.prototype.forEach) {
8135
8299
  }
8136
8300
  }));
8137
8301
  return new CompositeDisposable(subscription, timer);
8138
- });
8302
+ }, source);
8139
8303
  };
8140
8304
 
8141
8305
  /**
@@ -8261,68 +8425,64 @@ if (!Array.prototype.forEach) {
8261
8425
  return this.delayWithSelector(observableTimer(dueTime, isScheduler(scheduler) ? scheduler : timeoutScheduler), observableEmpty);
8262
8426
  };
8263
8427
 
8264
- /**
8265
- * Time shifts the observable sequence based on a subscription delay and a delay selector function for each element.
8266
- *
8267
- * @example
8268
- * 1 - res = source.delayWithSelector(function (x) { return Rx.Scheduler.timer(5000); }); // with selector only
8269
- * 1 - res = source.delayWithSelector(Rx.Observable.timer(2000), function (x) { return Rx.Observable.timer(x); }); // with delay and selector
8270
- *
8271
- * @param {Observable} [subscriptionDelay] Sequence indicating the delay for the subscription to the source.
8272
- * @param {Function} delayDurationSelector Selector function to retrieve a sequence indicating the delay for each given element.
8273
- * @returns {Observable} Time-shifted sequence.
8274
- */
8275
- observableProto.delayWithSelector = function (subscriptionDelay, delayDurationSelector) {
8276
- var source = this, subDelay, selector;
8277
- if (typeof subscriptionDelay === 'function') {
8278
- selector = subscriptionDelay;
8279
- } else {
8280
- subDelay = subscriptionDelay;
8281
- selector = delayDurationSelector;
8282
- }
8283
- return new AnonymousObservable(function (observer) {
8284
- var delays = new CompositeDisposable(), atEnd = false, done = function () {
8285
- if (atEnd && delays.length === 0) {
8286
- observer.onCompleted();
8287
- }
8288
- }, subscription = new SerialDisposable(), start = function () {
8289
- subscription.setDisposable(source.subscribe(function (x) {
8290
- var delay;
8291
- try {
8292
- delay = selector(x);
8293
- } catch (error) {
8294
- observer.onError(error);
8295
- return;
8296
- }
8297
- var d = new SingleAssignmentDisposable();
8298
- delays.add(d);
8299
- d.setDisposable(delay.subscribe(function () {
8300
- observer.onNext(x);
8301
- delays.remove(d);
8302
- done();
8303
- }, observer.onError.bind(observer), function () {
8304
- observer.onNext(x);
8305
- delays.remove(d);
8306
- done();
8307
- }));
8308
- }, observer.onError.bind(observer), function () {
8309
- atEnd = true;
8310
- subscription.dispose();
8311
- done();
8312
- }));
8313
- };
8428
+ /**
8429
+ * Time shifts the observable sequence based on a subscription delay and a delay selector function for each element.
8430
+ *
8431
+ * @example
8432
+ * 1 - res = source.delayWithSelector(function (x) { return Rx.Scheduler.timer(5000); }); // with selector only
8433
+ * 1 - res = source.delayWithSelector(Rx.Observable.timer(2000), function (x) { return Rx.Observable.timer(x); }); // with delay and selector
8434
+ *
8435
+ * @param {Observable} [subscriptionDelay] Sequence indicating the delay for the subscription to the source.
8436
+ * @param {Function} delayDurationSelector Selector function to retrieve a sequence indicating the delay for each given element.
8437
+ * @returns {Observable} Time-shifted sequence.
8438
+ */
8439
+ observableProto.delayWithSelector = function (subscriptionDelay, delayDurationSelector) {
8440
+ var source = this, subDelay, selector;
8441
+ if (typeof subscriptionDelay === 'function') {
8442
+ selector = subscriptionDelay;
8443
+ } else {
8444
+ subDelay = subscriptionDelay;
8445
+ selector = delayDurationSelector;
8446
+ }
8447
+ return new AnonymousObservable(function (observer) {
8448
+ var delays = new CompositeDisposable(), atEnd = false, done = function () {
8449
+ if (atEnd && delays.length === 0) { observer.onCompleted(); }
8450
+ }, subscription = new SerialDisposable(), start = function () {
8451
+ subscription.setDisposable(source.subscribe(function (x) {
8452
+ var delay;
8453
+ try {
8454
+ delay = selector(x);
8455
+ } catch (error) {
8456
+ observer.onError(error);
8457
+ return;
8458
+ }
8459
+ var d = new SingleAssignmentDisposable();
8460
+ delays.add(d);
8461
+ d.setDisposable(delay.subscribe(function () {
8462
+ observer.onNext(x);
8463
+ delays.remove(d);
8464
+ done();
8465
+ }, observer.onError.bind(observer), function () {
8466
+ observer.onNext(x);
8467
+ delays.remove(d);
8468
+ done();
8469
+ }));
8470
+ }, observer.onError.bind(observer), function () {
8471
+ atEnd = true;
8472
+ subscription.dispose();
8473
+ done();
8474
+ }));
8475
+ };
8314
8476
 
8315
- if (!subDelay) {
8316
- start();
8317
- } else {
8318
- subscription.setDisposable(subDelay.subscribe(function () {
8319
- start();
8320
- }, observer.onError.bind(observer), function () { start(); }));
8321
- }
8477
+ if (!subDelay) {
8478
+ start();
8479
+ } else {
8480
+ subscription.setDisposable(subDelay.subscribe(start, observer.onError.bind(observer), start));
8481
+ }
8322
8482
 
8323
- return new CompositeDisposable(subscription, delays);
8324
- });
8325
- };
8483
+ return new CompositeDisposable(subscription, delays);
8484
+ }, this);
8485
+ };
8326
8486
 
8327
8487
  /**
8328
8488
  * Returns the source observable sequence, switching to the other observable sequence if a timeout is signaled.
@@ -8390,26 +8550,22 @@ if (!Array.prototype.forEach) {
8390
8550
  observerWins() && observer.onCompleted();
8391
8551
  }));
8392
8552
  return new CompositeDisposable(subscription, timer);
8393
- });
8553
+ }, source);
8394
8554
  };
8395
8555
 
8396
8556
  /**
8397
- * Ignores values from an observable sequence which are followed by another value within a computed throttle duration.
8398
- *
8399
- * @example
8400
- * 1 - res = source.delayWithSelector(function (x) { return Rx.Scheduler.timer(x + x); });
8401
- *
8402
- * @param {Function} throttleDurationSelector Selector function to retrieve a sequence indicating the throttle duration for each given element.
8403
- * @returns {Observable} The throttled sequence.
8557
+ * Ignores values from an observable sequence which are followed by another value within a computed throttle duration.
8558
+ * @param {Function} durationSelector Selector function to retrieve a sequence indicating the throttle duration for each given element.
8559
+ * @returns {Observable} The debounced sequence.
8404
8560
  */
8405
- observableProto.throttleWithSelector = function (throttleDurationSelector) {
8561
+ observableProto.debounceWithSelector = function (durationSelector) {
8406
8562
  var source = this;
8407
8563
  return new AnonymousObservable(function (observer) {
8408
8564
  var value, hasValue = false, cancelable = new SerialDisposable(), id = 0;
8409
8565
  var subscription = source.subscribe(function (x) {
8410
8566
  var throttle;
8411
8567
  try {
8412
- throttle = throttleDurationSelector(x);
8568
+ throttle = durationSelector(x);
8413
8569
  } catch (e) {
8414
8570
  observer.onError(e);
8415
8571
  return;
@@ -8444,7 +8600,12 @@ if (!Array.prototype.forEach) {
8444
8600
  id++;
8445
8601
  });
8446
8602
  return new CompositeDisposable(subscription, cancelable);
8447
- });
8603
+ }, source);
8604
+ };
8605
+
8606
+ observableProto.throttleWithSelector = function () {
8607
+ deprecate('throttleWithSelector', 'debounceWithSelector');
8608
+ return this.debounceWithSelector.apply(this, arguments);
8448
8609
  };
8449
8610
 
8450
8611
  /**
@@ -8479,7 +8640,7 @@ if (!Array.prototype.forEach) {
8479
8640
  }
8480
8641
  observer.onCompleted();
8481
8642
  });
8482
- });
8643
+ }, source);
8483
8644
  };
8484
8645
 
8485
8646
  /**
@@ -8511,7 +8672,7 @@ if (!Array.prototype.forEach) {
8511
8672
  }
8512
8673
  observer.onCompleted();
8513
8674
  });
8514
- });
8675
+ }, source);
8515
8676
  };
8516
8677
 
8517
8678
  /**
@@ -8544,7 +8705,7 @@ if (!Array.prototype.forEach) {
8544
8705
  observer.onNext(res);
8545
8706
  observer.onCompleted();
8546
8707
  });
8547
- });
8708
+ }, source);
8548
8709
  };
8549
8710
 
8550
8711
  /**
@@ -8565,7 +8726,7 @@ if (!Array.prototype.forEach) {
8565
8726
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
8566
8727
  return new AnonymousObservable(function (observer) {
8567
8728
  return new CompositeDisposable(scheduler.scheduleWithRelative(duration, observer.onCompleted.bind(observer)), source.subscribe(observer));
8568
- });
8729
+ }, source);
8569
8730
  };
8570
8731
 
8571
8732
  /**
@@ -8592,7 +8753,7 @@ if (!Array.prototype.forEach) {
8592
8753
  return new CompositeDisposable(
8593
8754
  scheduler.scheduleWithRelative(duration, function () { open = true; }),
8594
8755
  source.subscribe(function (x) { open && observer.onNext(x); }, observer.onError.bind(observer), observer.onCompleted.bind(observer)));
8595
- });
8756
+ }, source);
8596
8757
  };
8597
8758
 
8598
8759
  /**
@@ -8620,7 +8781,7 @@ if (!Array.prototype.forEach) {
8620
8781
  function (x) { open && observer.onNext(x); },
8621
8782
  observer.onError.bind(observer),
8622
8783
  observer.onCompleted.bind(observer)));
8623
- });
8784
+ }, source);
8624
8785
  };
8625
8786
 
8626
8787
  /**
@@ -8638,7 +8799,34 @@ if (!Array.prototype.forEach) {
8638
8799
  return new CompositeDisposable(
8639
8800
  scheduler[schedulerMethod](endTime, observer.onCompleted.bind(observer)),
8640
8801
  source.subscribe(observer));
8641
- });
8802
+ }, source);
8803
+ };
8804
+
8805
+ /**
8806
+ * Returns an Observable that emits only the first item emitted by the source Observable during sequential time windows of a specified duration.
8807
+ * @param {Number} windowDuration time to wait before emitting another item after emitting the last item
8808
+ * @param {Scheduler} [scheduler] the Scheduler to use internally to manage the timers that handle timeout for each item. If not provided, defaults to Scheduler.timeout.
8809
+ * @returns {Observable} An Observable that performs the throttle operation.
8810
+ */
8811
+ observableProto.throttleFirst = function (windowDuration, scheduler) {
8812
+ isScheduler(scheduler) || (scheduler = timeoutScheduler);
8813
+ var duration = +windowDuration || 0;
8814
+ if (duration <= 0) { throw new RangeError('windowDuration cannot be less or equal zero.'); }
8815
+ var source = this;
8816
+ return new AnonymousObservable(function (observer) {
8817
+ var lastOnNext = 0;
8818
+ return source.subscribe(
8819
+ function (x) {
8820
+ var now = scheduler.now();
8821
+ if (lastOnNext === 0 || now - lastOnNext >= duration) {
8822
+ lastOnNext = now;
8823
+ observer.onNext(x);
8824
+ }
8825
+ },
8826
+ observer.onError.bind(observer),
8827
+ observer.onCompleted.bind(observer)
8828
+ );
8829
+ }, source);
8642
8830
  };
8643
8831
 
8644
8832
  /*
@@ -8687,7 +8875,7 @@ if (!Array.prototype.forEach) {
8687
8875
  }));
8688
8876
 
8689
8877
  return g;
8690
- });
8878
+ }, this);
8691
8879
  };
8692
8880
 
8693
8881
  /*
@@ -8750,11 +8938,11 @@ if (!Array.prototype.forEach) {
8750
8938
  }
8751
8939
  }));
8752
8940
  return g;
8753
- });
8941
+ }, this);
8754
8942
  };
8755
8943
 
8756
8944
  /**
8757
- * Executes a transducer to transform the observable sequence
8945
+ * Executes a transducer to transform the observable sequence
8758
8946
  * @param {Transducer} transducer A transducer to execute
8759
8947
  * @returns {Observable} An Observable sequence containing the results from the transducer.
8760
8948
  */
@@ -8778,17 +8966,17 @@ if (!Array.prototype.forEach) {
8778
8966
  return new AnonymousObservable(function(observer) {
8779
8967
  var xform = transducer(transformForObserver(observer));
8780
8968
  return source.subscribe(
8781
- function(v) {
8969
+ function(v) {
8782
8970
  try {
8783
8971
  xform.step(observer, v);
8784
8972
  } catch (e) {
8785
8973
  observer.onError(e);
8786
8974
  }
8787
- },
8788
- observer.onError.bind(observer),
8975
+ },
8976
+ observer.onError.bind(observer),
8789
8977
  function() { xform.result(observer); }
8790
8978
  );
8791
- });
8979
+ }, source);
8792
8980
  };
8793
8981
 
8794
8982
  /** Provides a set of extension methods for virtual time scheduling. */
@@ -9078,7 +9266,8 @@ if (!Array.prototype.forEach) {
9078
9266
  disposableEmpty;
9079
9267
  }
9080
9268
 
9081
- function AnonymousObservable(subscribe) {
9269
+ function AnonymousObservable(subscribe, parent) {
9270
+ this.source = parent;
9082
9271
  if (!(this instanceof AnonymousObservable)) {
9083
9272
  return new AnonymousObservable(subscribe);
9084
9273
  }
@@ -9111,66 +9300,59 @@ if (!Array.prototype.forEach) {
9111
9300
 
9112
9301
  }(Observable));
9113
9302
 
9114
- /** @private */
9115
- var AutoDetachObserver = (function (_super) {
9116
- inherits(AutoDetachObserver, _super);
9303
+ var AutoDetachObserver = (function (__super__) {
9304
+ inherits(AutoDetachObserver, __super__);
9117
9305
 
9118
- function AutoDetachObserver(observer) {
9119
- _super.call(this);
9120
- this.observer = observer;
9121
- this.m = new SingleAssignmentDisposable();
9122
- }
9306
+ function AutoDetachObserver(observer) {
9307
+ __super__.call(this);
9308
+ this.observer = observer;
9309
+ this.m = new SingleAssignmentDisposable();
9310
+ }
9123
9311
 
9124
- var AutoDetachObserverPrototype = AutoDetachObserver.prototype;
9312
+ var AutoDetachObserverPrototype = AutoDetachObserver.prototype;
9125
9313
 
9126
- AutoDetachObserverPrototype.next = function (value) {
9127
- var noError = false;
9128
- try {
9129
- this.observer.onNext(value);
9130
- noError = true;
9131
- } catch (e) {
9132
- throw e;
9133
- } finally {
9134
- if (!noError) {
9135
- this.dispose();
9136
- }
9137
- }
9138
- };
9314
+ AutoDetachObserverPrototype.next = function (value) {
9315
+ var noError = false;
9316
+ try {
9317
+ this.observer.onNext(value);
9318
+ noError = true;
9319
+ } catch (e) {
9320
+ throw e;
9321
+ } finally {
9322
+ !noError && this.dispose();
9323
+ }
9324
+ };
9139
9325
 
9140
- AutoDetachObserverPrototype.error = function (exn) {
9141
- try {
9142
- this.observer.onError(exn);
9143
- } catch (e) {
9144
- throw e;
9145
- } finally {
9146
- this.dispose();
9147
- }
9148
- };
9326
+ AutoDetachObserverPrototype.error = function (err) {
9327
+ try {
9328
+ this.observer.onError(err);
9329
+ } catch (e) {
9330
+ throw e;
9331
+ } finally {
9332
+ this.dispose();
9333
+ }
9334
+ };
9149
9335
 
9150
- AutoDetachObserverPrototype.completed = function () {
9151
- try {
9152
- this.observer.onCompleted();
9153
- } catch (e) {
9154
- throw e;
9155
- } finally {
9156
- this.dispose();
9157
- }
9158
- };
9336
+ AutoDetachObserverPrototype.completed = function () {
9337
+ try {
9338
+ this.observer.onCompleted();
9339
+ } catch (e) {
9340
+ throw e;
9341
+ } finally {
9342
+ this.dispose();
9343
+ }
9344
+ };
9159
9345
 
9160
- AutoDetachObserverPrototype.setDisposable = function (value) { this.m.setDisposable(value); };
9161
- AutoDetachObserverPrototype.getDisposable = function (value) { return this.m.getDisposable(); };
9162
- /* @private */
9163
- AutoDetachObserverPrototype.disposable = function (value) {
9164
- return arguments.length ? this.getDisposable() : setDisposable(value);
9165
- };
9346
+ AutoDetachObserverPrototype.setDisposable = function (value) { this.m.setDisposable(value); };
9347
+ AutoDetachObserverPrototype.getDisposable = function () { return this.m.getDisposable(); };
9166
9348
 
9167
- AutoDetachObserverPrototype.dispose = function () {
9168
- _super.prototype.dispose.call(this);
9169
- this.m.dispose();
9170
- };
9349
+ AutoDetachObserverPrototype.dispose = function () {
9350
+ __super__.prototype.dispose.call(this);
9351
+ this.m.dispose();
9352
+ };
9171
9353
 
9172
- return AutoDetachObserver;
9173
- }(AbstractObserver));
9354
+ return AutoDetachObserver;
9355
+ }(AbstractObserver));
9174
9356
 
9175
9357
  var GroupedObservable = (function (__super__) {
9176
9358
  inherits(GroupedObservable, __super__);
@@ -9466,4 +9648,7 @@ if (!Array.prototype.forEach) {
9466
9648
  root.Rx = Rx;
9467
9649
  }
9468
9650
 
9651
+ // All code before this point will be filtered from stack traces.
9652
+ var rEndingLine = captureLine();
9653
+
9469
9654
  }.call(this));