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

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

  function computePrecision(truePositives, falsePositives) {
    return truePositives / (truePositives + falsePositives);
  }

  function reducer({
    truePositives,
    falsePositives
  }, [trueValue, predictedValue]) {
    const tP = predictedValue === 1 && predictedValue === trueValue ? truePositives + 1 : truePositives;
    const fP = predictedValue === 1 && predictedValue !== trueValue ? falsePositives + 1 : falsePositives;
    return {
      truePositives: tP,
      falsePositives: fP
    };
  }

  const precision = function precision(initialState = {
    truePositives: 0,
    falsePositives: 0
  }) {
    return source$ => source$.pipe((0, _operators.scan)(reducer, initialState), (0, _operators.map)(({
      truePositives,
      falsePositives
    }) => computePrecision(truePositives, falsePositives)));
  };

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