(function (global, factory) {
  if (typeof define === "function" && define.amd) {
    define(["exports", "rxjs", "rxjs/operators", "./dirtyZScore"], factory);
  } else if (typeof exports !== "undefined") {
    factory(exports, require("rxjs"), require("rxjs/operators"), require("./dirtyZScore"));
  } else {
    var mod = {
      exports: {}
    };
    factory(mod.exports, global.rxjs, global.operators, global.dirtyZScore);
    global.dirtyR = mod.exports;
  }
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _rxjs, _operators, _dirtyZScore) {
  "use strict";

  Object.defineProperty(_exports, "__esModule", {
    value: true
  });
  _exports.default = void 0;
  _dirtyZScore = _interopRequireDefault(_dirtyZScore);

  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

  function numeratorReducer({
    numerator,
    index
  }, [xZScore, yZScore]) {
    return {
      index: index + 1,
      numerator: numerator + xZScore * yZScore
    };
  }

  const dirtyR = function dirtyR(initialState) {
    return source$ => {
      const sourceSub$ = source$.pipe((0, _operators.share)());
      const xZScore$ = sourceSub$.pipe((0, _operators.map)(pair => pair[0]), initialState && initialState.xZScoreStates && initialState.xZScoreStates[0] ? (0, _dirtyZScore.default)(initialState.xZScoreStates[0]) : (0, _dirtyZScore.default)());
      const yZScore$ = sourceSub$.pipe((0, _operators.map)(pair => pair[1]), (0, _dirtyZScore.default)(initialState && initialState.yZScoreState ? (0, _dirtyZScore.default)(initialState.yZScoreState) : (0, _dirtyZScore.default)()));
      const R$ = (0, _rxjs.zip)(xZScore$, yZScore$).pipe((0, _operators.scan)(numeratorReducer, {
        numerator: 0,
        index: 0
      }), (0, _operators.map)(({
        numerator,
        index
      }) => numerator / index));
      return R$;
    };
  };

  var _default = dirtyR;
  _exports.default = _default;
});
//# sourceMappingURL=dirtyR.js.map