last.js 861 B

1234567891011121314151617
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.last = void 0;
  4. var EmptyError_1 = require("../util/EmptyError");
  5. var filter_1 = require("./filter");
  6. var takeLast_1 = require("./takeLast");
  7. var throwIfEmpty_1 = require("./throwIfEmpty");
  8. var defaultIfEmpty_1 = require("./defaultIfEmpty");
  9. var identity_1 = require("../util/identity");
  10. function last(predicate, defaultValue) {
  11. var hasDefaultValue = arguments.length >= 2;
  12. return function (source) {
  13. return source.pipe(predicate ? filter_1.filter(function (v, i) { return predicate(v, i, source); }) : identity_1.identity, takeLast_1.takeLast(1), hasDefaultValue ? defaultIfEmpty_1.defaultIfEmpty(defaultValue) : throwIfEmpty_1.throwIfEmpty(function () { return new EmptyError_1.EmptyError(); }));
  14. };
  15. }
  16. exports.last = last;
  17. //# sourceMappingURL=last.js.map