veffect
Version:
powerful TypeScript validation library built on the robust foundation of Effect combining exceptional type safety, high performance, and developer experience. Taking inspiration from Effect's functional principles, VEffect delivers a balanced approach tha
115 lines (113 loc) • 3.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.update = exports.overwrite = exports.make = exports.isTestAnnotationMap = exports.get = exports.empty = exports.combine = exports.annotate = exports.TestAnnotationMapTypeId = void 0;
var _Function = /*#__PURE__*/require("./Function.js");
var HashMap = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./HashMap.js"));
var _Predicate = /*#__PURE__*/require("./Predicate.js");
function _getRequireWildcardCache(e) {
if ("function" != typeof WeakMap) return null;
var r = new WeakMap(),
t = new WeakMap();
return (_getRequireWildcardCache = function (e) {
return e ? t : r;
})(e);
}
function _interopRequireWildcard(e, r) {
if (!r && e && e.__esModule) return e;
if (null === e || "object" != typeof e && "function" != typeof e) return {
default: e
};
var t = _getRequireWildcardCache(r);
if (t && t.has(e)) return t.get(e);
var n = {
__proto__: null
},
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
}
return n.default = e, t && t.set(e, n), n;
}
/**
* @since 2.0.0
*/
/**
* @since 2.0.0
*/
const TestAnnotationMapTypeId = exports.TestAnnotationMapTypeId = /*#__PURE__*/Symbol.for("effect/TestAnnotationMap");
/** @internal */
class TestAnnotationMapImpl {
map;
[TestAnnotationMapTypeId] = TestAnnotationMapTypeId;
constructor(map) {
this.map = map;
}
}
/**
* @since 2.0.0
*/
const isTestAnnotationMap = u => (0, _Predicate.hasProperty)(u, TestAnnotationMapTypeId);
/**
* @since 2.0.0
*/
exports.isTestAnnotationMap = isTestAnnotationMap;
const empty = () => new TestAnnotationMapImpl(HashMap.empty());
/**
* @since 2.0.0
*/
exports.empty = empty;
const make = map => {
return new TestAnnotationMapImpl(map);
};
/**
* @since 2.0.0
*/
exports.make = make;
const overwrite = exports.overwrite = /*#__PURE__*/(0, _Function.dual)(3, (self, key, value) => make(HashMap.set(self.map, key, value)));
/**
* @since 2.0.0
*/
const update = exports.update = /*#__PURE__*/(0, _Function.dual)(3, (self, key, f) => {
let value = key.initial;
if (HashMap.has(self.map, key.identifier)) {
value = HashMap.unsafeGet(self.map, key.identifier);
}
return overwrite(self, key, f(value));
});
/**
* Retrieves the annotation of the specified type, or its default value if
* there is none.
*
* @since 2.0.0
*/
const get = exports.get = /*#__PURE__*/(0, _Function.dual)(2, (self, key) => {
if (HashMap.has(self.map, key.identifier)) {
return HashMap.unsafeGet(self.map, key.identifier);
}
return key.initial;
});
/**
* Appends the specified annotation to the annotation map.
*
* @since 2.0.0
*/
const annotate = exports.annotate = /*#__PURE__*/(0, _Function.dual)(3, (self, key, value) => update(self, key, _ => key.combine(_, value)));
/**
* @since 2.0.0
*/
const combine = exports.combine = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => {
let result = self.map;
for (const entry of that.map) {
if (HashMap.has(result, entry[0])) {
const value = HashMap.get(result, entry[0]);
result = HashMap.set(result, entry[0], entry[0].combine(value, entry[1]));
} else {
result = HashMap.set(result, entry[0], entry[1]);
}
}
return make(result);
});
//# sourceMappingURL=TestAnnotationMap.js.map