UNPKG

@akala/core

Version:
31 lines 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function polymorph(types) { types.reduce((previous, current, i) => { if (previous == current) console.warn(`there might be a conflict in polymorphism since types at position ${i - 1} and ${i} are identical`); return current; }, ''); return function (oldF) { return function (...args) { var finalArgs = []; let argsIndex = 0; for (let i = 0; i < types.length; i++) { if (typeof (args[argsIndex]) == types[i]) { finalArgs[i] = args[argsIndex]; argsIndex++; } } return oldF.apply(this, finalArgs); }; }; } exports.polymorph = polymorph; function Polymorph(types) { var readyToPolymorph = polymorph(types); return function (target, propertyKey, descriptor) { descriptor.value = readyToPolymorph(descriptor.value); }; } exports.Polymorph = Polymorph; //# sourceMappingURL=polymorph.js.map