"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.lazy = lazy;
const ErrorsAndWarnings_1 = require("./ErrorsAndWarnings");
function lazy(thunk) {
    let invoked = false;
    let result;
    let error;
    const f = () => {
        if (!invoked) {
            try {
                invoked = true;
                result = thunk();
            }
            catch (e) {
                error = (0, ErrorsAndWarnings_1.toError)(e);
                throw e;
            }
        }
        if (error != null)
            throw error;
        return result;
    };
    f.clear = () => {
        invoked = false;
        result = undefined;
        error = undefined;
    };
    return f;
}
//# sourceMappingURL=Lazy.js.map