export function memo(fn) {
    var cache = {};
    var getHash = function (args) { return args.reduce(function (acc, x) { return acc + x; }, ''); };
    var keysCount = 0;
    var limit = 1e4;
    return function () {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        try {
            var hash = getHash(args);
            var fromCache = cache[hash];
            if (fromCache) {
                return fromCache;
            }
            var result = fn.apply(void 0, args);
            cache[hash] = result;
            keysCount++;
            return result;
        }
        finally {
            if (keysCount > limit) {
                cache = {};
                keysCount = 0;
            }
        }
    };
}
//# sourceMappingURL=memo.js.map