rxjs-rails 2.3.11 → 2.3.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -307,7 +307,7 @@
307
307
  }
308
308
  }
309
309
  var size = 0;
310
- result = true;
310
+ var result = true;
311
311
 
312
312
  // add `a` and `b` to the stack of traversed objects
313
313
  stackA.push(a);
@@ -860,30 +860,30 @@ if (!Array.prototype.forEach) {
860
860
  });
861
861
  };
862
862
 
863
- var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
864
- this.scheduler = scheduler;
865
- this.state = state;
866
- this.action = action;
867
- this.dueTime = dueTime;
868
- this.comparer = comparer || defaultSubComparer;
869
- this.disposable = new SingleAssignmentDisposable();
870
- }
863
+ var ScheduledItem = Rx.internals.ScheduledItem = function (scheduler, state, action, dueTime, comparer) {
864
+ this.scheduler = scheduler;
865
+ this.state = state;
866
+ this.action = action;
867
+ this.dueTime = dueTime;
868
+ this.comparer = comparer || defaultSubComparer;
869
+ this.disposable = new SingleAssignmentDisposable();
870
+ }
871
871
 
872
- ScheduledItem.prototype.invoke = function () {
873
- this.disposable.setDisposable(this.invokeCore());
874
- };
872
+ ScheduledItem.prototype.invoke = function () {
873
+ this.disposable.setDisposable(this.invokeCore());
874
+ };
875
875
 
876
- ScheduledItem.prototype.compareTo = function (other) {
877
- return this.comparer(this.dueTime, other.dueTime);
878
- };
876
+ ScheduledItem.prototype.compareTo = function (other) {
877
+ return this.comparer(this.dueTime, other.dueTime);
878
+ };
879
879
 
880
- ScheduledItem.prototype.isCancelled = function () {
881
- return this.disposable.isDisposed;
882
- };
880
+ ScheduledItem.prototype.isCancelled = function () {
881
+ return this.disposable.isDisposed;
882
+ };
883
883
 
884
- ScheduledItem.prototype.invokeCore = function () {
885
- return this.action(this.scheduler, this.state);
886
- };
884
+ ScheduledItem.prototype.invokeCore = function () {
885
+ return this.action(this.scheduler, this.state);
886
+ };
887
887
 
888
888
  /** Provides a set of static properties to access commonly used schedulers. */
889
889
  var Scheduler = Rx.Scheduler = (function () {
@@ -895,54 +895,6 @@ if (!Array.prototype.forEach) {
895
895
  this._scheduleAbsolute = scheduleAbsolute;
896
896
  }
897
897
 
898
- function invokeRecImmediate(scheduler, pair) {
899
- var state = pair.first, action = pair.second, group = new CompositeDisposable(),
900
- recursiveAction = function (state1) {
901
- action(state1, function (state2) {
902
- var isAdded = false, isDone = false,
903
- d = scheduler.scheduleWithState(state2, function (scheduler1, state3) {
904
- if (isAdded) {
905
- group.remove(d);
906
- } else {
907
- isDone = true;
908
- }
909
- recursiveAction(state3);
910
- return disposableEmpty;
911
- });
912
- if (!isDone) {
913
- group.add(d);
914
- isAdded = true;
915
- }
916
- });
917
- };
918
- recursiveAction(state);
919
- return group;
920
- }
921
-
922
- function invokeRecDate(scheduler, pair, method) {
923
- var state = pair.first, action = pair.second, group = new CompositeDisposable(),
924
- recursiveAction = function (state1) {
925
- action(state1, function (state2, dueTime1) {
926
- var isAdded = false, isDone = false,
927
- d = scheduler[method].call(scheduler, state2, dueTime1, function (scheduler1, state3) {
928
- if (isAdded) {
929
- group.remove(d);
930
- } else {
931
- isDone = true;
932
- }
933
- recursiveAction(state3);
934
- return disposableEmpty;
935
- });
936
- if (!isDone) {
937
- group.add(d);
938
- isAdded = true;
939
- }
940
- });
941
- };
942
- recursiveAction(state);
943
- return group;
944
- }
945
-
946
898
  function invokeAction(scheduler, action) {
947
899
  action();
948
900
  return disposableEmpty;
@@ -1194,34 +1146,34 @@ if (!Array.prototype.forEach) {
1194
1146
  };
1195
1147
  }(Scheduler.prototype));
1196
1148
 
1197
- var SchedulePeriodicRecursive = Rx.internals.SchedulePeriodicRecursive = (function () {
1198
- function tick(command, recurse) {
1199
- recurse(0, this._period);
1200
- try {
1201
- this._state = this._action(this._state);
1202
- } catch (e) {
1203
- this._cancel.dispose();
1204
- throw e;
1205
- }
1206
- }
1149
+ var SchedulePeriodicRecursive = Rx.internals.SchedulePeriodicRecursive = (function () {
1150
+ function tick(command, recurse) {
1151
+ recurse(0, this._period);
1152
+ try {
1153
+ this._state = this._action(this._state);
1154
+ } catch (e) {
1155
+ this._cancel.dispose();
1156
+ throw e;
1157
+ }
1158
+ }
1207
1159
 
1208
- function SchedulePeriodicRecursive(scheduler, state, period, action) {
1209
- this._scheduler = scheduler;
1210
- this._state = state;
1211
- this._period = period;
1212
- this._action = action;
1213
- }
1160
+ function SchedulePeriodicRecursive(scheduler, state, period, action) {
1161
+ this._scheduler = scheduler;
1162
+ this._state = state;
1163
+ this._period = period;
1164
+ this._action = action;
1165
+ }
1214
1166
 
1215
- SchedulePeriodicRecursive.prototype.start = function () {
1216
- var d = new SingleAssignmentDisposable();
1217
- this._cancel = d;
1218
- d.setDisposable(this._scheduler.scheduleRecursiveWithRelativeAndState(0, this._period, tick.bind(this)));
1167
+ SchedulePeriodicRecursive.prototype.start = function () {
1168
+ var d = new SingleAssignmentDisposable();
1169
+ this._cancel = d;
1170
+ d.setDisposable(this._scheduler.scheduleRecursiveWithRelativeAndState(0, this._period, tick.bind(this)));
1219
1171
 
1220
- return d;
1221
- };
1172
+ return d;
1173
+ };
1222
1174
 
1223
- return SchedulePeriodicRecursive;
1224
- }());
1175
+ return SchedulePeriodicRecursive;
1176
+ }());
1225
1177
 
1226
1178
  /**
1227
1179
  * Gets a scheduler that schedules work immediately on the current thread.
@@ -1461,87 +1413,77 @@ if (!Array.prototype.forEach) {
1461
1413
  return new Scheduler(defaultNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1462
1414
  })();
1463
1415
 
1464
- /** @private */
1465
- var CatchScheduler = (function (_super) {
1416
+ var CatchScheduler = (function (__super__) {
1466
1417
 
1467
- function localNow() {
1468
- return this._scheduler.now();
1469
- }
1470
-
1471
- function scheduleNow(state, action) {
1472
- return this._scheduler.scheduleWithState(state, this._wrap(action));
1473
- }
1418
+ function scheduleNow(state, action) {
1419
+ return this._scheduler.scheduleWithState(state, this._wrap(action));
1420
+ }
1474
1421
 
1475
- function scheduleRelative(state, dueTime, action) {
1476
- return this._scheduler.scheduleWithRelativeAndState(state, dueTime, this._wrap(action));
1477
- }
1422
+ function scheduleRelative(state, dueTime, action) {
1423
+ return this._scheduler.scheduleWithRelativeAndState(state, dueTime, this._wrap(action));
1424
+ }
1478
1425
 
1479
- function scheduleAbsolute(state, dueTime, action) {
1480
- return this._scheduler.scheduleWithAbsoluteAndState(state, dueTime, this._wrap(action));
1481
- }
1426
+ function scheduleAbsolute(state, dueTime, action) {
1427
+ return this._scheduler.scheduleWithAbsoluteAndState(state, dueTime, this._wrap(action));
1428
+ }
1482
1429
 
1483
- inherits(CatchScheduler, _super);
1430
+ inherits(CatchScheduler, __super__);
1484
1431
 
1485
- /** @private */
1486
- function CatchScheduler(scheduler, handler) {
1487
- this._scheduler = scheduler;
1488
- this._handler = handler;
1489
- this._recursiveOriginal = null;
1490
- this._recursiveWrapper = null;
1491
- _super.call(this, localNow, scheduleNow, scheduleRelative, scheduleAbsolute);
1492
- }
1432
+ function CatchScheduler(scheduler, handler) {
1433
+ this._scheduler = scheduler;
1434
+ this._handler = handler;
1435
+ this._recursiveOriginal = null;
1436
+ this._recursiveWrapper = null;
1437
+ __super__.call(this, this._scheduler.now.bind(this._scheduler), scheduleNow, scheduleRelative, scheduleAbsolute);
1438
+ }
1493
1439
 
1494
- /** @private */
1495
- CatchScheduler.prototype._clone = function (scheduler) {
1496
- return new CatchScheduler(scheduler, this._handler);
1497
- };
1440
+ CatchScheduler.prototype._clone = function (scheduler) {
1441
+ return new CatchScheduler(scheduler, this._handler);
1442
+ };
1498
1443
 
1499
- /** @private */
1500
- CatchScheduler.prototype._wrap = function (action) {
1501
- var parent = this;
1502
- return function (self, state) {
1503
- try {
1504
- return action(parent._getRecursiveWrapper(self), state);
1505
- } catch (e) {
1506
- if (!parent._handler(e)) { throw e; }
1507
- return disposableEmpty;
1508
- }
1509
- };
1510
- };
1444
+ CatchScheduler.prototype._wrap = function (action) {
1445
+ var parent = this;
1446
+ return function (self, state) {
1447
+ try {
1448
+ return action(parent._getRecursiveWrapper(self), state);
1449
+ } catch (e) {
1450
+ if (!parent._handler(e)) { throw e; }
1451
+ return disposableEmpty;
1452
+ }
1453
+ };
1454
+ };
1511
1455
 
1512
- /** @private */
1513
- CatchScheduler.prototype._getRecursiveWrapper = function (scheduler) {
1514
- if (this._recursiveOriginal !== scheduler) {
1515
- this._recursiveOriginal = scheduler;
1516
- var wrapper = this._clone(scheduler);
1517
- wrapper._recursiveOriginal = scheduler;
1518
- wrapper._recursiveWrapper = wrapper;
1519
- this._recursiveWrapper = wrapper;
1520
- }
1521
- return this._recursiveWrapper;
1522
- };
1456
+ CatchScheduler.prototype._getRecursiveWrapper = function (scheduler) {
1457
+ if (this._recursiveOriginal !== scheduler) {
1458
+ this._recursiveOriginal = scheduler;
1459
+ var wrapper = this._clone(scheduler);
1460
+ wrapper._recursiveOriginal = scheduler;
1461
+ wrapper._recursiveWrapper = wrapper;
1462
+ this._recursiveWrapper = wrapper;
1463
+ }
1464
+ return this._recursiveWrapper;
1465
+ };
1523
1466
 
1524
- /** @private */
1525
- CatchScheduler.prototype.schedulePeriodicWithState = function (state, period, action) {
1526
- var self = this, failed = false, d = new SingleAssignmentDisposable();
1467
+ CatchScheduler.prototype.schedulePeriodicWithState = function (state, period, action) {
1468
+ var self = this, failed = false, d = new SingleAssignmentDisposable();
1527
1469
 
1528
- d.setDisposable(this._scheduler.schedulePeriodicWithState(state, period, function (state1) {
1529
- if (failed) { return null; }
1530
- try {
1531
- return action(state1);
1532
- } catch (e) {
1533
- failed = true;
1534
- if (!self._handler(e)) { throw e; }
1535
- d.dispose();
1536
- return null;
1537
- }
1538
- }));
1470
+ d.setDisposable(this._scheduler.schedulePeriodicWithState(state, period, function (state1) {
1471
+ if (failed) { return null; }
1472
+ try {
1473
+ return action(state1);
1474
+ } catch (e) {
1475
+ failed = true;
1476
+ if (!self._handler(e)) { throw e; }
1477
+ d.dispose();
1478
+ return null;
1479
+ }
1480
+ }));
1539
1481
 
1540
- return d;
1541
- };
1482
+ return d;
1483
+ };
1542
1484
 
1543
- return CatchScheduler;
1544
- }(Scheduler));
1485
+ return CatchScheduler;
1486
+ }(Scheduler));
1545
1487
 
1546
1488
  /**
1547
1489
  * Represents a notification to an observer.
@@ -1620,14 +1562,14 @@ if (!Array.prototype.forEach) {
1620
1562
  function _acceptObservable(observer) { return observer.onError(this.exception); }
1621
1563
  function toString () { return 'OnError(' + this.exception + ')'; }
1622
1564
 
1623
- return function (exception) {
1565
+ return function (e) {
1624
1566
  var notification = new Notification('E');
1625
- notification.exception = exception;
1567
+ notification.exception = e;
1626
1568
  notification._accept = _accept;
1627
1569
  notification._acceptObservable = _acceptObservable;
1628
1570
  notification.toString = toString;
1629
1571
  return notification;
1630
- };
1572
+ };
1631
1573
  }());
1632
1574
 
1633
1575
  /**
@@ -1636,17 +1578,17 @@ if (!Array.prototype.forEach) {
1636
1578
  */
1637
1579
  var notificationCreateOnCompleted = Notification.createOnCompleted = (function () {
1638
1580
 
1639
- function _accept (onNext, onError, onCompleted) { return onCompleted(); }
1640
- function _acceptObservable(observer) { return observer.onCompleted(); }
1641
- function toString () { return 'OnCompleted()'; }
1581
+ function _accept (onNext, onError, onCompleted) { return onCompleted(); }
1582
+ function _acceptObservable(observer) { return observer.onCompleted(); }
1583
+ function toString () { return 'OnCompleted()'; }
1642
1584
 
1643
- return function () {
1644
- var notification = new Notification('C');
1645
- notification._accept = _accept;
1646
- notification._acceptObservable = _acceptObservable;
1647
- notification.toString = toString;
1648
- return notification;
1649
- };
1585
+ return function () {
1586
+ var notification = new Notification('C');
1587
+ notification._accept = _accept;
1588
+ notification._acceptObservable = _acceptObservable;
1589
+ notification.toString = toString;
1590
+ return notification;
1591
+ };
1650
1592
  }());
1651
1593
 
1652
1594
  var Enumerator = Rx.internals.Enumerator = function (next) {
@@ -2380,7 +2322,7 @@ if (!Array.prototype.forEach) {
2380
2322
  * @param {Any} [thisArg] The context to use calling the mapFn if provided.
2381
2323
  * @param {Scheduler} [scheduler] Optional scheduler to use for scheduling. If not provided, defaults to Scheduler.currentThread.
2382
2324
  */
2383
- Observable.from = function (iterable, mapFn, thisArg, scheduler) {
2325
+ var observableFrom = Observable.from = function (iterable, mapFn, thisArg, scheduler) {
2384
2326
  if (iterable == null) {
2385
2327
  throw new Error('iterable cannot be null.')
2386
2328
  }
@@ -2398,7 +2340,13 @@ if (!Array.prototype.forEach) {
2398
2340
  if (i < len || objIsIterable) {
2399
2341
  var result;
2400
2342
  if (objIsIterable) {
2401
- var next = it.next();
2343
+ var next;
2344
+ try {
2345
+ next = it.next();
2346
+ } catch (e) {
2347
+ observer.onError(e);
2348
+ return;
2349
+ }
2402
2350
  if (next.done) {
2403
2351
  observer.onCompleted();
2404
2352
  return;
@@ -2406,7 +2354,7 @@ if (!Array.prototype.forEach) {
2406
2354
 
2407
2355
  result = next.value;
2408
2356
  } else {
2409
- result = list[i];
2357
+ result = !!list.charAt ? list.charAt(i) : list[i];
2410
2358
  }
2411
2359
 
2412
2360
  if (mapFn && isCallable(mapFn)) {
@@ -3688,47 +3636,50 @@ if (!Array.prototype.forEach) {
3688
3636
  });
3689
3637
  };
3690
3638
 
3691
- function concatMap(source, selector, thisArg) {
3692
- return source.map(function (x, i) {
3693
- var result = selector.call(thisArg, x, i);
3694
- return isPromise(result) ? observableFromPromise(result) : result;
3695
- }).concatAll();
3696
- }
3639
+ function concatMap(source, selector, thisArg) {
3640
+ return source.map(function (x, i) {
3641
+ var result = selector.call(thisArg, x, i, source);
3642
+ isPromise(result) && (result = observableFromPromise(result));
3643
+ (Array.isArray(result) || isIterable(result)) && (result = observableFrom(result));
3644
+ return result;
3645
+ }).concatAll();
3646
+ }
3697
3647
 
3698
- /**
3699
- * One of the Following:
3700
- * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
3701
- *
3702
- * @example
3703
- * var res = source.concatMap(function (x) { return Rx.Observable.range(0, x); });
3704
- * Or:
3705
- * Projects each element of an observable sequence to an observable sequence, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence.
3706
- *
3707
- * var res = source.concatMap(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
3708
- * Or:
3709
- * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
3710
- *
3711
- * var res = source.concatMap(Rx.Observable.fromArray([1,2,3]));
3712
- * @param selector A transform function to apply to each element or an observable sequence to project each element from the
3713
- * source sequence onto which could be either an observable or Promise.
3714
- * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
3715
- * @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.
3716
- */
3717
- observableProto.selectConcat = observableProto.concatMap = function (selector, resultSelector, thisArg) {
3718
- if (resultSelector) {
3719
- return this.concatMap(function (x, i) {
3720
- var selectorResult = selector(x, i),
3721
- result = isPromise(selectorResult) ? observableFromPromise(selectorResult) : selectorResult;
3722
-
3723
- return result.map(function (y) {
3724
- return resultSelector(x, y, i);
3725
- });
3726
- });
3727
- }
3728
- return typeof selector === 'function' ?
3729
- concatMap(this, selector, thisArg) :
3730
- concatMap(this, function () { return selector; });
3731
- };
3648
+ /**
3649
+ * One of the Following:
3650
+ * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
3651
+ *
3652
+ * @example
3653
+ * var res = source.concatMap(function (x) { return Rx.Observable.range(0, x); });
3654
+ * Or:
3655
+ * Projects each element of an observable sequence to an observable sequence, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence.
3656
+ *
3657
+ * var res = source.concatMap(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
3658
+ * Or:
3659
+ * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
3660
+ *
3661
+ * var res = source.concatMap(Rx.Observable.fromArray([1,2,3]));
3662
+ * @param {Function} selector A transform function to apply to each element or an observable sequence to project each element from the
3663
+ * source sequence onto which could be either an observable or Promise.
3664
+ * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
3665
+ * @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
+ */
3667
+ observableProto.selectConcat = observableProto.concatMap = function (selector, resultSelector, thisArg) {
3668
+ if (typeof selector === 'function' && typeof resultSelector === 'function') {
3669
+ return this.concatMap(function (x, i) {
3670
+ var selectorResult = selector(x, i);
3671
+ isPromise(selectorResult) && (selectorResult = observableFromPromise(selectorResult));
3672
+ (Array.isArray(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
3673
+
3674
+ return selectorResult.map(function (y, i2) {
3675
+ return resultSelector(x, y, i, i2);
3676
+ });
3677
+ });
3678
+ }
3679
+ return typeof selector === 'function' ?
3680
+ concatMap(this, selector, thisArg) :
3681
+ concatMap(this, function () { return selector; });
3682
+ };
3732
3683
 
3733
3684
  /**
3734
3685
  * Projects each notification of an observable sequence to an observable sequence and concats the resulting observable sequences into one observable sequence.
@@ -4010,48 +3961,50 @@ if (!Array.prototype.forEach) {
4010
3961
  return this.map(function (x) { return x[prop]; });
4011
3962
  };
4012
3963
 
4013
- function flatMap(source, selector, thisArg) {
4014
- return source.map(function (x, i) {
4015
- var result = selector.call(thisArg, x, i);
4016
- return isPromise(result) ? observableFromPromise(result) : result;
4017
- }).mergeObservable();
4018
- }
3964
+ function flatMap(source, selector, thisArg) {
3965
+ return source.map(function (x, i) {
3966
+ var result = selector.call(thisArg, x, i, source);
3967
+ isPromise(result) && (result = observableFromPromise(result));
3968
+ (Array.isArray(result) || isIterable(result)) && (result = observableFrom(result));
3969
+ return result;
3970
+ }).mergeObservable();
3971
+ }
4019
3972
 
4020
- /**
4021
- * One of the Following:
4022
- * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
4023
- *
4024
- * @example
4025
- * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); });
4026
- * Or:
4027
- * Projects each element of an observable sequence to an observable sequence, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence.
4028
- *
4029
- * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
4030
- * Or:
4031
- * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
4032
- *
4033
- * var res = source.selectMany(Rx.Observable.fromArray([1,2,3]));
4034
- * @param selector A transform function to apply to each element or an observable sequence to project each element from the
4035
- * source sequence onto which could be either an observable or Promise.
4036
- * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
4037
- * @param {Any} [thisArg] Object to use as this when executing callback.
4038
- * @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.
4039
- */
4040
- observableProto.selectMany = observableProto.flatMap = function (selector, resultSelector, thisArg) {
4041
- if (resultSelector) {
4042
- return this.flatMap(function (x, i) {
4043
- var selectorResult = selector(x, i),
4044
- result = isPromise(selectorResult) ? observableFromPromise(selectorResult) : selectorResult;
4045
-
4046
- return result.map(function (y) {
4047
- return resultSelector(x, y, i);
4048
- });
4049
- }, thisArg);
4050
- }
4051
- return typeof selector === 'function' ?
4052
- flatMap(this, selector, thisArg) :
4053
- flatMap(this, function () { return selector; });
4054
- };
3973
+ /**
3974
+ * One of the Following:
3975
+ * Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
3976
+ *
3977
+ * @example
3978
+ * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); });
3979
+ * Or:
3980
+ * Projects each element of an observable sequence to an observable sequence, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence.
3981
+ *
3982
+ * var res = source.selectMany(function (x) { return Rx.Observable.range(0, x); }, function (x, y) { return x + y; });
3983
+ * Or:
3984
+ * Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
3985
+ *
3986
+ * var res = source.selectMany(Rx.Observable.fromArray([1,2,3]));
3987
+ * @param {Function} selector A transform function to apply to each element or an observable sequence to project each element from the source sequence onto which could be either an observable or Promise.
3988
+ * @param {Function} [resultSelector] A transform function to apply to each element of the intermediate sequence.
3989
+ * @param {Any} [thisArg] Object to use as this when executing callback.
3990
+ * @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
+ */
3992
+ observableProto.selectMany = observableProto.flatMap = function (selector, resultSelector, thisArg) {
3993
+ if (typeof selector === 'function' && typeof resultSelector === 'function') {
3994
+ return this.flatMap(function (x, i) {
3995
+ var selectorResult = selector(x, i);
3996
+ isPromise(selectorResult) && (selectorResult = observableFromPromise(selectorResult));
3997
+ (Array.isArray(selectorResult) || isIterable(selectorResult)) && (selectorResult = observableFrom(selectorResult));
3998
+
3999
+ return selectorResult.map(function (y, i2) {
4000
+ return resultSelector(x, y, i, i2);
4001
+ });
4002
+ }, thisArg);
4003
+ }
4004
+ return typeof selector === 'function' ?
4005
+ flatMap(this, selector, thisArg) :
4006
+ flatMap(this, function () { return selector; });
4007
+ };
4055
4008
 
4056
4009
  /**
4057
4010
  * Projects each notification of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
@@ -4305,46 +4258,40 @@ if (!Array.prototype.forEach) {
4305
4258
  return x[0];
4306
4259
  }
4307
4260
 
4308
- /**
4309
- * 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.
4310
- * For aggregation behavior with incremental intermediate results, see Observable.scan.
4311
- * @example
4312
- * 1 - res = source.aggregate(function (acc, x) { return acc + x; });
4313
- * 2 - res = source.aggregate(0, function (acc, x) { return acc + x; });
4314
- * @param {Mixed} [seed] The initial accumulator value.
4315
- * @param {Function} accumulator An accumulator function to be invoked on each element.
4316
- * @returns {Observable} An observable sequence containing a single element with the final accumulator value.
4317
- */
4318
- observableProto.aggregate = function () {
4319
- var seed, hasSeed, accumulator;
4320
- if (arguments.length === 2) {
4321
- seed = arguments[0];
4322
- hasSeed = true;
4323
- accumulator = arguments[1];
4324
- } else {
4325
- accumulator = arguments[0];
4326
- }
4327
- return hasSeed ? this.scan(seed, accumulator).startWith(seed).finalValue() : this.scan(accumulator).finalValue();
4328
- };
4261
+ /**
4262
+ * 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
+ * For aggregation behavior with incremental intermediate results, see Observable.scan.
4264
+ * @param {Mixed} [seed] The initial accumulator value.
4265
+ * @param {Function} accumulator An accumulator function to be invoked on each element.
4266
+ * @returns {Observable} An observable sequence containing a single element with the final accumulator value.
4267
+ */
4268
+ observableProto.aggregate = function () {
4269
+ var seed, hasSeed, accumulator;
4270
+ if (arguments.length === 2) {
4271
+ seed = arguments[0];
4272
+ hasSeed = true;
4273
+ accumulator = arguments[1];
4274
+ } else {
4275
+ accumulator = arguments[0];
4276
+ }
4277
+ return hasSeed ? this.scan(seed, accumulator).startWith(seed).finalValue() : this.scan(accumulator).finalValue();
4278
+ };
4329
4279
 
4330
- /**
4331
- * 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.
4332
- * For aggregation behavior with incremental intermediate results, see Observable.scan.
4333
- * @example
4334
- * 1 - res = source.reduce(function (acc, x) { return acc + x; });
4335
- * 2 - res = source.reduce(function (acc, x) { return acc + x; }, 0);
4336
- * @param {Function} accumulator An accumulator function to be invoked on each element.
4337
- * @param {Any} [seed] The initial accumulator value.
4338
- * @returns {Observable} An observable sequence containing a single element with the final accumulator value.
4339
- */
4340
- observableProto.reduce = function (accumulator) {
4341
- var seed, hasSeed;
4342
- if (arguments.length === 2) {
4343
- hasSeed = true;
4344
- seed = arguments[1];
4345
- }
4346
- return hasSeed ? this.scan(seed, accumulator).startWith(seed).finalValue() : this.scan(accumulator).finalValue();
4347
- };
4280
+ /**
4281
+ * 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.
4282
+ * For aggregation behavior with incremental intermediate results, see Observable.scan.
4283
+ * @param {Function} accumulator An accumulator function to be invoked on each element.
4284
+ * @param {Any} [seed] The initial accumulator value.
4285
+ * @returns {Observable} An observable sequence containing a single element with the final accumulator value.
4286
+ */
4287
+ observableProto.reduce = function (accumulator) {
4288
+ var seed, hasSeed;
4289
+ if (arguments.length === 2) {
4290
+ hasSeed = true;
4291
+ seed = arguments[1];
4292
+ }
4293
+ return hasSeed ? this.scan(seed, accumulator).startWith(seed).finalValue() : this.scan(accumulator).finalValue();
4294
+ };
4348
4295
 
4349
4296
  /**
4350
4297
  * Determines whether any element of an observable sequence satisfies a condition if present, else if any items are in the sequence.
@@ -4551,33 +4498,27 @@ if (!Array.prototype.forEach) {
4551
4498
  });
4552
4499
  };
4553
4500
 
4554
- /**
4555
- * 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.
4556
- * @example
4557
- * var res = res = source.average();
4558
- * var res = res = source.average(function (x) { return x.value; });
4559
- * @param {Function} [selector] A transform function to apply to each element.
4560
- * @param {Any} [thisArg] Object to use as this when executing callback.
4561
- * @returns {Observable} An observable sequence containing a single element with the average of the sequence of values.
4562
- */
4563
- observableProto.average = function (keySelector, thisArg) {
4564
- return keySelector ?
4565
- this.select(keySelector, thisArg).average() :
4566
- this.scan({
4567
- sum: 0,
4568
- count: 0
4569
- }, function (prev, cur) {
4570
- return {
4571
- sum: prev.sum + cur,
4572
- count: prev.count + 1
4573
- };
4574
- }).finalValue().select(function (s) {
4575
- if (s.count === 0) {
4576
- throw new Error('The input sequence was empty');
4577
- }
4578
- return s.sum / s.count;
4579
- });
4580
- };
4501
+ /**
4502
+ * 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.
4503
+ * @param {Function} [selector] A transform function to apply to each element.
4504
+ * @param {Any} [thisArg] Object to use as this when executing callback.
4505
+ * @returns {Observable} An observable sequence containing a single element with the average of the sequence of values.
4506
+ */
4507
+ observableProto.average = function (keySelector, thisArg) {
4508
+ return keySelector && isFunction(keySelector) ?
4509
+ this.select(keySelector, thisArg).average() :
4510
+ this.scan({sum: 0, count: 0 }, function (prev, cur) {
4511
+ return {
4512
+ sum: prev.sum + cur,
4513
+ count: prev.count + 1
4514
+ };
4515
+ }).finalValue().map(function (s) {
4516
+ if (s.count === 0) {
4517
+ throw new Error('The input sequence was empty');
4518
+ }
4519
+ return s.sum / s.count;
4520
+ });
4521
+ };
4581
4522
 
4582
4523
  function sequenceEqualArray(first, second, comparer) {
4583
4524
  return new AnonymousObservable(function (observer) {
@@ -4999,36 +4940,17 @@ if (!Array.prototype.forEach) {
4999
4940
  };
5000
4941
  }
5001
4942
 
5002
- var fnString = 'function';
4943
+ var fnString = 'function',
4944
+ throwString = 'throw';
5003
4945
 
5004
4946
  function toThunk(obj, ctx) {
5005
- if (Array.isArray(obj)) {
5006
- return objectToThunk.call(ctx, obj);
5007
- }
5008
-
5009
- if (isGeneratorFunction(obj)) {
5010
- return observableSpawn(obj.call(ctx));
5011
- }
5012
-
5013
- if (isGenerator(obj)) {
5014
- return observableSpawn(obj);
5015
- }
5016
-
5017
- if (isObservable(obj)) {
5018
- return observableToThunk(obj);
5019
- }
5020
-
5021
- if (isPromise(obj)) {
5022
- return promiseToThunk(obj);
5023
- }
5024
-
5025
- if (typeof obj === fnString) {
5026
- return obj;
5027
- }
5028
-
5029
- if (isObject(obj) || Array.isArray(obj)) {
5030
- return objectToThunk.call(ctx, obj);
5031
- }
4947
+ if (Array.isArray(obj)) { return objectToThunk.call(ctx, obj); }
4948
+ if (isGeneratorFunction(obj)) { return observableSpawn(obj.call(ctx)); }
4949
+ if (isGenerator(obj)) { return observableSpawn(obj); }
4950
+ if (isObservable(obj)) { return observableToThunk(obj); }
4951
+ if (isPromise(obj)) { return promiseToThunk(obj); }
4952
+ if (typeof obj === fnString) { return obj; }
4953
+ if (isObject(obj) || Array.isArray(obj)) { return objectToThunk.call(ctx, obj); }
5032
4954
 
5033
4955
  return obj;
5034
4956
  }
@@ -5080,7 +5002,7 @@ if (!Array.prototype.forEach) {
5080
5002
  }
5081
5003
  }
5082
5004
 
5083
- function observableToThink(observable) {
5005
+ function observableToThunk(observable) {
5084
5006
  return function (fn) {
5085
5007
  var value, hasValue = false;
5086
5008
  observable.subscribe(
@@ -5104,7 +5026,7 @@ if (!Array.prototype.forEach) {
5104
5026
  }
5105
5027
 
5106
5028
  function isObservable(obj) {
5107
- return obj && obj.prototype.subscribe === fnString;
5029
+ return obj && typeof obj.subscribe === fnString;
5108
5030
  }
5109
5031
 
5110
5032
  function isGeneratorFunction(obj) {
@@ -5112,7 +5034,7 @@ if (!Array.prototype.forEach) {
5112
5034
  }
5113
5035
 
5114
5036
  function isGenerator(obj) {
5115
- return obj && typeof obj.next === fnString && typeof obj.throw === fnString;
5037
+ return obj && typeof obj.next === fnString && typeof obj[throwString] === fnString;
5116
5038
  }
5117
5039
 
5118
5040
  function isObject(val) {
@@ -5129,7 +5051,7 @@ if (!Array.prototype.forEach) {
5129
5051
 
5130
5052
  return function (done) {
5131
5053
  var ctx = this,
5132
- gen = fan;
5054
+ gen = fn;
5133
5055
 
5134
5056
  if (isGenFun) {
5135
5057
  var args = slice.call(arguments),
@@ -5156,7 +5078,7 @@ if (!Array.prototype.forEach) {
5156
5078
 
5157
5079
  if (err) {
5158
5080
  try {
5159
- ret = gen.throw(err);
5081
+ ret = gen[throwString](err);
5160
5082
  } catch (e) {
5161
5083
  return exit(e);
5162
5084
  }
@@ -5240,6 +5162,13 @@ if (!Array.prototype.forEach) {
5240
5162
  }
5241
5163
  };
5242
5164
 
5165
+ function error(err) {
5166
+ if (!err) { return; }
5167
+ timeoutScheduler.schedule(function(){
5168
+ throw err;
5169
+ });
5170
+ }
5171
+
5243
5172
  /**
5244
5173
  * Invokes the specified function asynchronously on the specified scheduler, surfacing the result through an observable sequence.
5245
5174
  *
@@ -8160,7 +8089,7 @@ if (!Array.prototype.forEach) {
8160
8089
  * @returns {Observable} The source sequence switching to the other sequence in case of a timeout.
8161
8090
  */
8162
8091
  observableProto.timeout = function (dueTime, other, scheduler) {
8163
- other || (other = observableThrow(new Error('Timeout')));
8092
+ (other == null || typeof other === 'string') && (other = observableThrow(new Error(other || 'Timeout')));
8164
8093
  isScheduler(scheduler) || (scheduler = timeoutScheduler);
8165
8094
 
8166
8095
  var source = this, schedulerMethod = dueTime instanceof Date ?
@@ -8824,6 +8753,44 @@ if (!Array.prototype.forEach) {
8824
8753
  });
8825
8754
  };
8826
8755
 
8756
+ /**
8757
+ * Executes a transducer to transform the observable sequence
8758
+ * @param {Transducer} transducer A transducer to execute
8759
+ * @returns {Observable} An Observable sequence containing the results from the transducer.
8760
+ */
8761
+ observableProto.transduce = function(transducer) {
8762
+ var source = this;
8763
+
8764
+ function transformForObserver(observer) {
8765
+ return {
8766
+ init: function() {
8767
+ return observer;
8768
+ },
8769
+ step: function(obs, input) {
8770
+ return obs.onNext(input);
8771
+ },
8772
+ result: function(obs) {
8773
+ return obs.onCompleted();
8774
+ }
8775
+ };
8776
+ }
8777
+
8778
+ return new AnonymousObservable(function(observer) {
8779
+ var xform = transducer(transformForObserver(observer));
8780
+ return source.subscribe(
8781
+ function(v) {
8782
+ try {
8783
+ xform.step(observer, v);
8784
+ } catch (e) {
8785
+ observer.onError(e);
8786
+ }
8787
+ },
8788
+ observer.onError.bind(observer),
8789
+ function() { xform.result(observer); }
8790
+ );
8791
+ });
8792
+ };
8793
+
8827
8794
  /** Provides a set of extension methods for virtual time scheduling. */
8828
8795
  Rx.VirtualTimeScheduler = (function (__super__) {
8829
8796