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

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

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

  const reducer = function reducer({
    valueCounts,
    keyCount
  }, nextValue) {
    return {
      keyCount: valueCounts[nextValue] ? keyCount : keyCount + 1,
      valueCounts: { ...valueCounts,
        [nextValue]: valueCounts[nextValue] ? valueCounts[nextValue] + 1 : 1
      }
    };
  };

  const countValues = function countValues(initialState = {
    valueCounts: {},
    keyCount: 0
  }) {
    return source$ => source$.pipe((0, _operators.scan)(reducer, initialState), (0, _operators.map)(({
      valueCounts
    }) => valueCounts), (0, _operators.map)(valueCounts => (0, _toPairs.default)(valueCounts)), (0, _operators.map)(pairs => pairs.map(p => {
      const num = parseFloat(p[0]);
      return {
        value: (0, _isNaN2.default)(num) ? p[0] : num,
        count: p[1]
      };
    })));
  };

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