UNPKG

@rimbu/bimap

Version:

A bidirectional immutable Map of keys and values for TypeScript

89 lines 3.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BiMapContext = void 0; var custom_1 = require("@rimbu/bimap/custom"); var stream_1 = require("@rimbu/stream"); var custom_2 = require("@rimbu/stream/custom"); var BiMapContext = /** @class */ (function () { function BiMapContext(keyValueContext, valueKeyContext) { var _this = this; this.keyValueContext = keyValueContext; this.valueKeyContext = valueKeyContext; this._empty = Object.freeze(new custom_1.BiMapEmpty(this)); this.empty = function () { return _this._empty; }; this.of = function () { var entries = []; for (var _i = 0; _i < arguments.length; _i++) { entries[_i] = arguments[_i]; } return _this.from(entries); }; this.from = function () { var sources = []; for (var _i = 0; _i < arguments.length; _i++) { sources[_i] = arguments[_i]; } if (sources.length === 1) { var source = sources[0]; if (source instanceof custom_1.BiMapNonEmptyImpl && source.context === _this) return source; } var builder = _this.builder(); var i = -1; var length = sources.length; while (++i < length) { var source = sources[i]; if ((0, custom_2.isEmptyStreamSourceInstance)(source)) continue; if (builder.isEmpty && source instanceof custom_1.BiMapNonEmptyImpl && source.context === _this) { if (i === length - 1) return source; builder = source.toBuilder(); continue; } builder.addEntries(source); } return builder.build(); }; this.builder = function () { return new custom_1.BiMapBuilder(_this); }; this.reducer = function (source) { return stream_1.Reducer.create(function () { return undefined === source ? _this.builder() : _this.from(source).toBuilder(); }, function (builder, entry) { builder.addEntry(entry); return builder; }, function (builder) { return builder.build(); }); }; } Object.defineProperty(BiMapContext.prototype, "typeTag", { get: function () { return 'BiMap'; }, enumerable: false, configurable: true }); Object.defineProperty(BiMapContext.prototype, "_types", { get: function () { return undefined; }, enumerable: false, configurable: true }); BiMapContext.prototype.createNonEmptyImpl = function (keyValueMap, valueKeyMap) { return new custom_1.BiMapNonEmptyImpl(this, keyValueMap, valueKeyMap); }; BiMapContext.prototype.createBuilder = function (source) { return new custom_1.BiMapBuilder(this, source); }; return BiMapContext; }()); exports.BiMapContext = BiMapContext; //# sourceMappingURL=context.cjs.map