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
@@ -46,7 +46,11 @@
46
46
  defaultSubComparer = helpers.defaultSubComparer,
47
47
  isFunction = helpers.isFunction,
48
48
  isPromise = helpers.isPromise,
49
- observableFromPromise = Observable.fromPromise;
49
+ isArrayLike = helpers.isArrayLike,
50
+ isIterable = helpers.isIterable,
51
+ observableFromPromise = Observable.fromPromise,
52
+ observableFrom = Observable.from,
53
+ deprecate = helpers.deprecate;
50
54
 
51
55
  // Defaults
52
56
  var argumentOutOfRange = 'Argument out of range',
@@ -67,7 +71,7 @@
67
71
  observer.onCompleted();
68
72
  }
69
73
  });
70
- });
74
+ }, source);
71
75
  };
72
76
 
73
77
  function extremaBy(source, keySelector, comparer) {
@@ -102,24 +106,24 @@
102
106
  observer.onNext(list);
103
107
  observer.onCompleted();
104
108
  });
105
- });
109
+ }, source);
106
110
  }
107
111
 
108
- function firstOnly(x) {
109
- if (x.length === 0) {
110
- throw new Error(sequenceContainsNoElements);
111
- }
112
- return x[0];
113
- }
112
+ function firstOnly(x) {
113
+ if (x.length === 0) { throw new Error(sequenceContainsNoElements); }
114
+ return x[0];
115
+ }
114
116
 
115
117
  /**
116
118
  * 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.
117
119
  * For aggregation behavior with incremental intermediate results, see Observable.scan.
120
+ * @deprecated Use #reduce instead
118
121
  * @param {Mixed} [seed] The initial accumulator value.
119
122
  * @param {Function} accumulator An accumulator function to be invoked on each element.
120
123
  * @returns {Observable} An observable sequence containing a single element with the final accumulator value.
121
124
  */
122
125
  observableProto.aggregate = function () {
126
+ deprecate('aggregate', 'reduce');
123
127
  var seed, hasSeed, accumulator;
124
128
  if (arguments.length === 2) {
125
129
  seed = arguments[0];
@@ -147,28 +151,31 @@
147
151
  return hasSeed ? this.scan(seed, accumulator).startWith(seed).finalValue() : this.scan(accumulator).finalValue();
148
152
  };
149
153
 
150
- /**
151
- * Determines whether any element of an observable sequence satisfies a condition if present, else if any items are in the sequence.
152
- * @example
153
- * var result = source.any();
154
- * var result = source.any(function (x) { return x > 3; });
155
- * @param {Function} [predicate] A function to test each element for a condition.
156
- * @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.
157
- */
158
- observableProto.some = observableProto.any = function (predicate, thisArg) {
159
- var source = this;
160
- return predicate ?
161
- source.where(predicate, thisArg).any() :
162
- new AnonymousObservable(function (observer) {
163
- return source.subscribe(function () {
164
- observer.onNext(true);
165
- observer.onCompleted();
166
- }, observer.onError.bind(observer), function () {
167
- observer.onNext(false);
168
- observer.onCompleted();
169
- });
170
- });
171
- };
154
+ /**
155
+ * Determines whether any element of an observable sequence satisfies a condition if present, else if any items are in the sequence.
156
+ * @param {Function} [predicate] A function to test each element for a condition.
157
+ * @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.
158
+ */
159
+ observableProto.some = function (predicate, thisArg) {
160
+ var source = this;
161
+ return predicate ?
162
+ source.filter(predicate, thisArg).some() :
163
+ new AnonymousObservable(function (observer) {
164
+ return source.subscribe(function () {
165
+ observer.onNext(true);
166
+ observer.onCompleted();
167
+ }, observer.onError.bind(observer), function () {
168
+ observer.onNext(false);
169
+ observer.onCompleted();
170
+ });
171
+ }, source);
172
+ };
173
+
174
+ /** @deprecated use #some instead */
175
+ observableProto.any = function () {
176
+ deprecate('any', 'some');
177
+ return this.some.apply(this, arguments);
178
+ };
172
179
 
173
180
  /**
174
181
  * Determines whether an observable sequence is empty.
@@ -178,22 +185,21 @@
178
185
  return this.any().map(not);
179
186
  };
180
187
 
181
- /**
182
- * Determines whether all elements of an observable sequence satisfy a condition.
183
- *
184
- * 1 - res = source.all(function (value) { return value.length > 3; });
185
- * @memberOf Observable#
186
- * @param {Function} [predicate] A function to test each element for a condition.
187
- * @param {Any} [thisArg] Object to use as this when executing callback.
188
- * @returns {Observable} An observable sequence containing a single element determining whether all elements in the source sequence pass the test in the specified predicate.
189
- */
190
- observableProto.every = observableProto.all = function (predicate, thisArg) {
191
- return this.where(function (v) {
192
- return !predicate(v);
193
- }, thisArg).any().select(function (b) {
194
- return !b;
195
- });
196
- };
188
+ /**
189
+ * Determines whether all elements of an observable sequence satisfy a condition.
190
+ * @param {Function} [predicate] A function to test each element for a condition.
191
+ * @param {Any} [thisArg] Object to use as this when executing callback.
192
+ * @returns {Observable} An observable sequence containing a single element determining whether all elements in the source sequence pass the test in the specified predicate.
193
+ */
194
+ observableProto.every = function (predicate, thisArg) {
195
+ return this.filter(function (v) { return !predicate(v); }, thisArg).some().map(not);
196
+ };
197
+
198
+ /** @deprecated use #every instead */
199
+ observableProto.all = function () {
200
+ deprecate('all', 'every');
201
+ return this.every.apply(this, arguments);
202
+ };
197
203
 
198
204
  /**
199
205
  * Determines whether an observable sequence contains a specified element with an optional equality comparer.
@@ -226,7 +232,7 @@
226
232
  observer.onNext(false);
227
233
  observer.onCompleted();
228
234
  });
229
- });
235
+ }, this);
230
236
  };
231
237
 
232
238
  /**
@@ -275,13 +281,11 @@
275
281
  observer.onNext(-1);
276
282
  observer.onCompleted();
277
283
  });
278
- });
284
+ }, source);
279
285
  };
286
+
280
287
  /**
281
288
  * 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.
282
- * @example
283
- * var res = source.sum();
284
- * var res = source.sum(function (x) { return x.value; });
285
289
  * @param {Function} [selector] A transform function to apply to each element.
286
290
  * @param {Any} [thisArg] Object to use as this when executing callback.
287
291
  * @returns {Observable} An observable sequence containing a single element with the sum of the values in the source sequence.
@@ -289,68 +293,62 @@
289
293
  observableProto.sum = function (keySelector, thisArg) {
290
294
  return keySelector && isFunction(keySelector) ?
291
295
  this.map(keySelector, thisArg).sum() :
292
- this.aggregate(0, function (prev, curr) {
296
+ this.reduce(function (prev, curr) {
293
297
  return prev + curr;
294
- });
298
+ }, 0);
295
299
  };
296
300
 
297
- /**
298
- * Returns the elements in an observable sequence with the minimum key value according to the specified comparer.
299
- * @example
300
- * var res = source.minBy(function (x) { return x.value; });
301
- * var res = source.minBy(function (x) { return x.value; }, function (x, y) { return x - y; });
302
- * @param {Function} keySelector Key selector function.
303
- * @param {Function} [comparer] Comparer used to compare key values.
304
- * @returns {Observable} An observable sequence containing a list of zero or more elements that have a minimum key value.
305
- */
306
- observableProto.minBy = function (keySelector, comparer) {
307
- comparer || (comparer = defaultSubComparer);
308
- return extremaBy(this, keySelector, function (x, y) {
309
- return comparer(x, y) * -1;
310
- });
311
- };
301
+ /**
302
+ * Returns the elements in an observable sequence with the minimum key value according to the specified comparer.
303
+ * @example
304
+ * var res = source.minBy(function (x) { return x.value; });
305
+ * var res = source.minBy(function (x) { return x.value; }, function (x, y) { return x - y; });
306
+ * @param {Function} keySelector Key selector function.
307
+ * @param {Function} [comparer] Comparer used to compare key values.
308
+ * @returns {Observable} An observable sequence containing a list of zero or more elements that have a minimum key value.
309
+ */
310
+ observableProto.minBy = function (keySelector, comparer) {
311
+ comparer || (comparer = defaultSubComparer);
312
+ return extremaBy(this, keySelector, function (x, y) { return comparer(x, y) * -1; });
313
+ };
312
314
 
313
- /**
314
- * Returns the minimum element in an observable sequence according to the optional comparer else a default greater than less than check.
315
- * @example
316
- * var res = source.min();
317
- * var res = source.min(function (x, y) { return x.value - y.value; });
318
- * @param {Function} [comparer] Comparer used to compare elements.
319
- * @returns {Observable} An observable sequence containing a single element with the minimum element in the source sequence.
320
- */
321
- observableProto.min = function (comparer) {
322
- return this.minBy(identity, comparer).select(function (x) {
323
- return firstOnly(x);
324
- });
325
- };
315
+ /**
316
+ * Returns the minimum element in an observable sequence according to the optional comparer else a default greater than less than check.
317
+ * @example
318
+ * var res = source.min();
319
+ * var res = source.min(function (x, y) { return x.value - y.value; });
320
+ * @param {Function} [comparer] Comparer used to compare elements.
321
+ * @returns {Observable} An observable sequence containing a single element with the minimum element in the source sequence.
322
+ */
323
+ observableProto.min = function (comparer) {
324
+ return this.minBy(identity, comparer).map(function (x) { return firstOnly(x); });
325
+ };
326
326
 
327
- /**
328
- * Returns the elements in an observable sequence with the maximum key value according to the specified comparer.
329
- * @example
330
- * var res = source.maxBy(function (x) { return x.value; });
331
- * var res = source.maxBy(function (x) { return x.value; }, function (x, y) { return x - y;; });
332
- * @param {Function} keySelector Key selector function.
333
- * @param {Function} [comparer] Comparer used to compare key values.
334
- * @returns {Observable} An observable sequence containing a list of zero or more elements that have a maximum key value.
335
- */
336
- observableProto.maxBy = function (keySelector, comparer) {
337
- comparer || (comparer = defaultSubComparer);
338
- return extremaBy(this, keySelector, comparer);
339
- };
327
+ /**
328
+ * Returns the elements in an observable sequence with the maximum key value according to the specified comparer.
329
+ * @example
330
+ * var res = source.maxBy(function (x) { return x.value; });
331
+ * var res = source.maxBy(function (x) { return x.value; }, function (x, y) { return x - y;; });
332
+ * @param {Function} keySelector Key selector function.
333
+ * @param {Function} [comparer] Comparer used to compare key values.
334
+ * @returns {Observable} An observable sequence containing a list of zero or more elements that have a maximum key value.
335
+ */
336
+ observableProto.maxBy = function (keySelector, comparer) {
337
+ comparer || (comparer = defaultSubComparer);
338
+ return extremaBy(this, keySelector, comparer);
339
+ };
340
340
 
341
- /**
342
- * Returns the maximum value in an observable sequence according to the specified comparer.
343
- * @example
344
- * var res = source.max();
345
- * var res = source.max(function (x, y) { return x.value - y.value; });
346
- * @param {Function} [comparer] Comparer used to compare elements.
347
- * @returns {Observable} An observable sequence containing a single element with the maximum element in the source sequence.
348
- */
349
- observableProto.max = function (comparer) {
350
- return this.maxBy(identity, comparer).select(function (x) {
351
- return firstOnly(x);
352
- });
353
- };
341
+ /**
342
+ * Returns the maximum value in an observable sequence according to the specified comparer.
343
+ * @example
344
+ * var res = source.max();
345
+ * var res = source.max(function (x, y) { return x.value - y.value; });
346
+ * @param {Function} [comparer] Comparer used to compare elements.
347
+ * @returns {Observable} An observable sequence containing a single element with the maximum element in the source sequence.
348
+ */
349
+ observableProto.max = function (comparer) {
350
+ return this.maxBy(identity, comparer).map(function (x) { return firstOnly(x); });
351
+ };
354
352
 
355
353
  /**
356
354
  * 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.
@@ -374,28 +372,6 @@
374
372
  });
375
373
  };
376
374
 
377
- function sequenceEqualArray(first, second, comparer) {
378
- return new AnonymousObservable(function (observer) {
379
- var count = 0, len = second.length;
380
- return first.subscribe(function (value) {
381
- var equal = false;
382
- try {
383
- count < len && (equal = comparer(value, second[count++]));
384
- } catch (e) {
385
- observer.onError(e);
386
- return;
387
- }
388
- if (!equal) {
389
- observer.onNext(false);
390
- observer.onCompleted();
391
- }
392
- }, observer.onError.bind(observer), function () {
393
- observer.onNext(count === len);
394
- observer.onCompleted();
395
- });
396
- });
397
- }
398
-
399
375
  /**
400
376
  * Determines whether two sequences are equal by comparing the elements pairwise using a specified equality comparer.
401
377
  *
@@ -411,9 +387,6 @@
411
387
  observableProto.sequenceEqual = function (second, comparer) {
412
388
  var first = this;
413
389
  comparer || (comparer = defaultComparer);
414
- if (Array.isArray(second)) {
415
- return sequenceEqualArray(first, second, comparer);
416
- }
417
390
  return new AnonymousObservable(function (observer) {
418
391
  var donel = false, doner = false, ql = [], qr = [];
419
392
  var subscription1 = first.subscribe(function (x) {
@@ -449,6 +422,7 @@
449
422
  }
450
423
  });
451
424
 
425
+ (isArrayLike(second) || isIterable(second)) && (second = observableFrom(second));
452
426
  isPromise(second) && (second = observableFromPromise(second));
453
427
  var subscription2 = second.subscribe(function (x) {
454
428
  var equal;
@@ -483,55 +457,52 @@
483
457
  }
484
458
  });
485
459
  return new CompositeDisposable(subscription1, subscription2);
486
- });
460
+ }, first);
487
461
  };
488
462
 
489
- function elementAtOrDefault(source, index, hasDefault, defaultValue) {
490
- if (index < 0) {
491
- throw new Error(argumentOutOfRange);
463
+ function elementAtOrDefault(source, index, hasDefault, defaultValue) {
464
+ if (index < 0) { throw new Error(argumentOutOfRange); }
465
+ return new AnonymousObservable(function (observer) {
466
+ var i = index;
467
+ return source.subscribe(function (x) {
468
+ if (i-- === 0) {
469
+ observer.onNext(x);
470
+ observer.onCompleted();
492
471
  }
493
- return new AnonymousObservable(function (observer) {
494
- var i = index;
495
- return source.subscribe(function (x) {
496
- if (i === 0) {
497
- observer.onNext(x);
498
- observer.onCompleted();
499
- }
500
- i--;
501
- }, observer.onError.bind(observer), function () {
502
- if (!hasDefault) {
503
- observer.onError(new Error(argumentOutOfRange));
504
- } else {
505
- observer.onNext(defaultValue);
506
- observer.onCompleted();
507
- }
508
- });
509
- });
510
- }
472
+ }, observer.onError.bind(observer), function () {
473
+ if (!hasDefault) {
474
+ observer.onError(new Error(argumentOutOfRange));
475
+ } else {
476
+ observer.onNext(defaultValue);
477
+ observer.onCompleted();
478
+ }
479
+ });
480
+ }, source);
481
+ }
511
482
 
512
- /**
513
- * Returns the element at a specified index in a sequence.
514
- * @example
515
- * var res = source.elementAt(5);
516
- * @param {Number} index The zero-based index of the element to retrieve.
517
- * @returns {Observable} An observable sequence that produces the element at the specified position in the source sequence.
518
- */
519
- observableProto.elementAt = function (index) {
520
- return elementAtOrDefault(this, index, false);
521
- };
483
+ /**
484
+ * Returns the element at a specified index in a sequence.
485
+ * @example
486
+ * var res = source.elementAt(5);
487
+ * @param {Number} index The zero-based index of the element to retrieve.
488
+ * @returns {Observable} An observable sequence that produces the element at the specified position in the source sequence.
489
+ */
490
+ observableProto.elementAt = function (index) {
491
+ return elementAtOrDefault(this, index, false);
492
+ };
522
493
 
523
- /**
524
- * Returns the element at a specified index in a sequence or a default value if the index is out of range.
525
- * @example
526
- * var res = source.elementAtOrDefault(5);
527
- * var res = source.elementAtOrDefault(5, 0);
528
- * @param {Number} index The zero-based index of the element to retrieve.
529
- * @param [defaultValue] The default value if the index is outside the bounds of the source sequence.
530
- * @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.
531
- */
532
- observableProto.elementAtOrDefault = function (index, defaultValue) {
533
- return elementAtOrDefault(this, index, true, defaultValue);
534
- };
494
+ /**
495
+ * Returns the element at a specified index in a sequence or a default value if the index is out of range.
496
+ * @example
497
+ * var res = source.elementAtOrDefault(5);
498
+ * var res = source.elementAtOrDefault(5, 0);
499
+ * @param {Number} index The zero-based index of the element to retrieve.
500
+ * @param [defaultValue] The default value if the index is outside the bounds of the source sequence.
501
+ * @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.
502
+ */
503
+ observableProto.elementAtOrDefault = function (index, defaultValue) {
504
+ return elementAtOrDefault(this, index, true, defaultValue);
505
+ };
535
506
 
536
507
  function singleOrDefaultAsync(source, hasDefault, defaultValue) {
537
508
  return new AnonymousObservable(function (observer) {
@@ -551,14 +522,11 @@
551
522
  observer.onCompleted();
552
523
  }
553
524
  });
554
- });
525
+ }, source);
555
526
  }
556
527
 
557
528
  /**
558
529
  * 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.
559
- * @example
560
- * var res = res = source.single();
561
- * var res = res = source.single(function (x) { return x === 42; });
562
530
  * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
563
531
  * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
564
532
  * @returns {Observable} Sequence containing the single element in the observable sequence that satisfies the condition in the predicate.
@@ -588,211 +556,198 @@
588
556
  singleOrDefaultAsync(this, true, defaultValue);
589
557
  };
590
558
 
591
- function firstOrDefaultAsync(source, hasDefault, defaultValue) {
592
- return new AnonymousObservable(function (observer) {
593
- return source.subscribe(function (x) {
594
- observer.onNext(x);
595
- observer.onCompleted();
596
- }, observer.onError.bind(observer), function () {
597
- if (!hasDefault) {
598
- observer.onError(new Error(sequenceContainsNoElements));
599
- } else {
600
- observer.onNext(defaultValue);
601
- observer.onCompleted();
602
- }
603
- });
604
- });
605
- }
559
+ function firstOrDefaultAsync(source, hasDefault, defaultValue) {
560
+ return new AnonymousObservable(function (observer) {
561
+ return source.subscribe(function (x) {
562
+ observer.onNext(x);
563
+ observer.onCompleted();
564
+ }, observer.onError.bind(observer), function () {
565
+ if (!hasDefault) {
566
+ observer.onError(new Error(sequenceContainsNoElements));
567
+ } else {
568
+ observer.onNext(defaultValue);
569
+ observer.onCompleted();
570
+ }
571
+ });
572
+ }, source);
573
+ }
606
574
 
607
- /**
608
- * Returns the first element of an observable sequence that satisfies the condition in the predicate if present else the first item in the sequence.
609
- * @example
610
- * var res = res = source.first();
611
- * var res = res = source.first(function (x) { return x > 3; });
612
- * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
613
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
614
- * @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.
615
- */
616
- observableProto.first = function (predicate, thisArg) {
617
- return predicate ?
618
- this.where(predicate, thisArg).first() :
619
- firstOrDefaultAsync(this, false);
620
- };
575
+ /**
576
+ * Returns the first element of an observable sequence that satisfies the condition in the predicate if present else the first item in the sequence.
577
+ * @example
578
+ * var res = res = source.first();
579
+ * var res = res = source.first(function (x) { return x > 3; });
580
+ * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
581
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
582
+ * @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.
583
+ */
584
+ observableProto.first = function (predicate, thisArg) {
585
+ return predicate ?
586
+ this.where(predicate, thisArg).first() :
587
+ firstOrDefaultAsync(this, false);
588
+ };
621
589
 
622
- /**
623
- * Returns the first element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
624
- * @example
625
- * var res = res = source.firstOrDefault();
626
- * var res = res = source.firstOrDefault(function (x) { return x > 3; });
627
- * var res = source.firstOrDefault(function (x) { return x > 3; }, 0);
628
- * var res = source.firstOrDefault(null, 0);
629
- * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
630
- * @param {Any} [defaultValue] The default value if no such element exists. If not specified, defaults to null.
631
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
632
- * @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.
633
- */
634
- observableProto.firstOrDefault = function (predicate, defaultValue, thisArg) {
635
- return predicate ?
636
- this.where(predicate).firstOrDefault(null, defaultValue) :
637
- firstOrDefaultAsync(this, true, defaultValue);
638
- };
590
+ /**
591
+ * Returns the first element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
592
+ * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
593
+ * @param {Any} [defaultValue] The default value if no such element exists. If not specified, defaults to null.
594
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
595
+ * @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.
596
+ */
597
+ observableProto.firstOrDefault = function (predicate, defaultValue, thisArg) {
598
+ return predicate ?
599
+ this.where(predicate).firstOrDefault(null, defaultValue) :
600
+ firstOrDefaultAsync(this, true, defaultValue);
601
+ };
639
602
 
640
- function lastOrDefaultAsync(source, hasDefault, defaultValue) {
641
- return new AnonymousObservable(function (observer) {
642
- var value = defaultValue, seenValue = false;
643
- return source.subscribe(function (x) {
644
- value = x;
645
- seenValue = true;
646
- }, observer.onError.bind(observer), function () {
647
- if (!seenValue && !hasDefault) {
648
- observer.onError(new Error(sequenceContainsNoElements));
649
- } else {
650
- observer.onNext(value);
651
- observer.onCompleted();
652
- }
653
- });
654
- });
655
- }
603
+ function lastOrDefaultAsync(source, hasDefault, defaultValue) {
604
+ return new AnonymousObservable(function (observer) {
605
+ var value = defaultValue, seenValue = false;
606
+ return source.subscribe(function (x) {
607
+ value = x;
608
+ seenValue = true;
609
+ }, observer.onError.bind(observer), function () {
610
+ if (!seenValue && !hasDefault) {
611
+ observer.onError(new Error(sequenceContainsNoElements));
612
+ } else {
613
+ observer.onNext(value);
614
+ observer.onCompleted();
615
+ }
616
+ });
617
+ }, source);
618
+ }
656
619
 
657
- /**
658
- * Returns the last element of an observable sequence that satisfies the condition in the predicate if specified, else the last element.
659
- * @example
660
- * var res = source.last();
661
- * var res = source.last(function (x) { return x > 3; });
662
- * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
663
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
664
- * @returns {Observable} Sequence containing the last element in the observable sequence that satisfies the condition in the predicate.
665
- */
666
- observableProto.last = function (predicate, thisArg) {
667
- return predicate ?
668
- this.where(predicate, thisArg).last() :
669
- lastOrDefaultAsync(this, false);
670
- };
620
+ /**
621
+ * Returns the last element of an observable sequence that satisfies the condition in the predicate if specified, else the last element.
622
+ * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
623
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
624
+ * @returns {Observable} Sequence containing the last element in the observable sequence that satisfies the condition in the predicate.
625
+ */
626
+ observableProto.last = function (predicate, thisArg) {
627
+ return predicate ?
628
+ this.where(predicate, thisArg).last() :
629
+ lastOrDefaultAsync(this, false);
630
+ };
671
631
 
672
- /**
673
- * Returns the last element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
674
- * @example
675
- * var res = source.lastOrDefault();
676
- * var res = source.lastOrDefault(function (x) { return x > 3; });
677
- * var res = source.lastOrDefault(function (x) { return x > 3; }, 0);
678
- * var res = source.lastOrDefault(null, 0);
679
- * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
680
- * @param [defaultValue] The default value if no such element exists. If not specified, defaults to null.
681
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
682
- * @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.
683
- */
684
- observableProto.lastOrDefault = function (predicate, defaultValue, thisArg) {
685
- return predicate ?
686
- this.where(predicate, thisArg).lastOrDefault(null, defaultValue) :
687
- lastOrDefaultAsync(this, true, defaultValue);
688
- };
632
+ /**
633
+ * Returns the last element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
634
+ * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
635
+ * @param [defaultValue] The default value if no such element exists. If not specified, defaults to null.
636
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
637
+ * @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.
638
+ */
639
+ observableProto.lastOrDefault = function (predicate, defaultValue, thisArg) {
640
+ return predicate ?
641
+ this.where(predicate, thisArg).lastOrDefault(null, defaultValue) :
642
+ lastOrDefaultAsync(this, true, defaultValue);
643
+ };
689
644
 
690
- function findValue (source, predicate, thisArg, yieldIndex) {
691
- return new AnonymousObservable(function (observer) {
692
- var i = 0;
693
- return source.subscribe(function (x) {
694
- var shouldRun;
695
- try {
696
- shouldRun = predicate.call(thisArg, x, i, source);
697
- } catch(e) {
698
- observer.onError(e);
699
- return;
700
- }
701
- if (shouldRun) {
702
- observer.onNext(yieldIndex ? i : x);
703
- observer.onCompleted();
704
- } else {
705
- i++;
706
- }
707
- }, observer.onError.bind(observer), function () {
708
- observer.onNext(yieldIndex ? -1 : undefined);
709
- observer.onCompleted();
710
- });
711
- });
712
- }
645
+ function findValue (source, predicate, thisArg, yieldIndex) {
646
+ return new AnonymousObservable(function (observer) {
647
+ var i = 0;
648
+ return source.subscribe(function (x) {
649
+ var shouldRun;
650
+ try {
651
+ shouldRun = predicate.call(thisArg, x, i, source);
652
+ } catch (e) {
653
+ observer.onError(e);
654
+ return;
655
+ }
656
+ if (shouldRun) {
657
+ observer.onNext(yieldIndex ? i : x);
658
+ observer.onCompleted();
659
+ } else {
660
+ i++;
661
+ }
662
+ }, observer.onError.bind(observer), function () {
663
+ observer.onNext(yieldIndex ? -1 : undefined);
664
+ observer.onCompleted();
665
+ });
666
+ }, source);
667
+ }
713
668
 
714
- /**
715
- * Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire Observable sequence.
716
- * @param {Function} predicate The predicate that defines the conditions of the element to search for.
717
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
718
- * @returns {Observable} An Observable sequence with the first element that matches the conditions defined by the specified predicate, if found; otherwise, undefined.
719
- */
720
- observableProto.find = function (predicate, thisArg) {
721
- return findValue(this, predicate, thisArg, false);
722
- };
669
+ /**
670
+ * Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire Observable sequence.
671
+ * @param {Function} predicate The predicate that defines the conditions of the element to search for.
672
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
673
+ * @returns {Observable} An Observable sequence with the first element that matches the conditions defined by the specified predicate, if found; otherwise, undefined.
674
+ */
675
+ observableProto.find = function (predicate, thisArg) {
676
+ return findValue(this, predicate, thisArg, false);
677
+ };
723
678
 
724
- /**
725
- * Searches for an element that matches the conditions defined by the specified predicate, and returns
726
- * an Observable sequence with the zero-based index of the first occurrence within the entire Observable sequence.
727
- * @param {Function} predicate The predicate that defines the conditions of the element to search for.
728
- * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
729
- * @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.
730
- */
731
- observableProto.findIndex = function (predicate, thisArg) {
732
- return findValue(this, predicate, thisArg, true);
733
- };
679
+ /**
680
+ * Searches for an element that matches the conditions defined by the specified predicate, and returns
681
+ * an Observable sequence with the zero-based index of the first occurrence within the entire Observable sequence.
682
+ * @param {Function} predicate The predicate that defines the conditions of the element to search for.
683
+ * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
684
+ * @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.
685
+ */
686
+ observableProto.findIndex = function (predicate, thisArg) {
687
+ return findValue(this, predicate, thisArg, true);
688
+ };
734
689
 
735
- if (!!root.Set) {
736
- /**
737
- * Converts the observable sequence to a Set if it exists.
738
- * @returns {Observable} An observable sequence with a single value of a Set containing the values from the observable sequence.
739
- */
740
- observableProto.toSet = function () {
741
- var source = this;
742
- return new AnonymousObservable(function (observer) {
743
- var s = new root.Set();
744
- return source.subscribe(
745
- s.add.bind(s),
746
- observer.onError.bind(observer),
747
- function () {
748
- observer.onNext(s);
749
- observer.onCompleted();
750
- });
751
- });
752
- };
753
- }
754
690
 
755
- if (!!root.Map) {
756
- /**
757
- * Converts the observable sequence to a Map if it exists.
758
- * @param {Function} keySelector A function which produces the key for the Map.
759
- * @param {Function} [elementSelector] An optional function which produces the element for the Map. If not present, defaults to the value from the observable sequence.
760
- * @returns {Observable} An observable sequence with a single value of a Map containing the values from the observable sequence.
761
- */
762
- observableProto.toMap = function (keySelector, elementSelector) {
763
- var source = this;
764
- return new AnonymousObservable(function (observer) {
765
- var m = new root.Map();
766
- return source.subscribe(
767
- function (x) {
768
- var key;
691
+ /**
692
+ * Converts the observable sequence to a Set if it exists.
693
+ * @returns {Observable} An observable sequence with a single value of a Set containing the values from the observable sequence.
694
+ */
695
+ observableProto.toSet = function () {
696
+ if (typeof root.Set === 'undefined') { throw new TypeError(); }
697
+ var source = this;
698
+ return new AnonymousObservable(function (observer) {
699
+ var s = new root.Set();
700
+ return source.subscribe(
701
+ s.add.bind(s),
702
+ observer.onError.bind(observer),
703
+ function () {
704
+ observer.onNext(s);
705
+ observer.onCompleted();
706
+ });
707
+ }, source);
708
+ };
709
+
710
+
711
+ /**
712
+ * Converts the observable sequence to a Map if it exists.
713
+ * @param {Function} keySelector A function which produces the key for the Map.
714
+ * @param {Function} [elementSelector] An optional function which produces the element for the Map. If not present, defaults to the value from the observable sequence.
715
+ * @returns {Observable} An observable sequence with a single value of a Map containing the values from the observable sequence.
716
+ */
717
+ observableProto.toMap = function (keySelector, elementSelector) {
718
+ if (typeof root.Map === 'undefined') { throw new TypeError(); }
719
+ var source = this;
720
+ return new AnonymousObservable(function (observer) {
721
+ var m = new root.Map();
722
+ return source.subscribe(
723
+ function (x) {
724
+ var key;
725
+ try {
726
+ key = keySelector(x);
727
+ } catch (e) {
728
+ observer.onError(e);
729
+ return;
730
+ }
731
+
732
+ var element = x;
733
+ if (elementSelector) {
769
734
  try {
770
- key = keySelector(x);
735
+ element = elementSelector(x);
771
736
  } catch (e) {
772
737
  observer.onError(e);
773
738
  return;
774
739
  }
740
+ }
775
741
 
776
- var element = x;
777
- if (elementSelector) {
778
- try {
779
- element = elementSelector(x);
780
- } catch (e) {
781
- observer.onError(e);
782
- return;
783
- }
784
- }
785
-
786
- m.set(key, element);
787
- },
788
- observer.onError.bind(observer),
789
- function () {
790
- observer.onNext(m);
791
- observer.onCompleted();
792
- });
793
- });
794
- };
795
- }
742
+ m.set(key, element);
743
+ },
744
+ observer.onError.bind(observer),
745
+ function () {
746
+ observer.onNext(m);
747
+ observer.onCompleted();
748
+ });
749
+ }, source);
750
+ };
796
751
 
797
752
  return Rx;
798
753
  }));