"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.noop = noop;
exports.once = once;
exports.silentWrapAsync = silentWrapAsync;
exports.trampoline = trampoline;
/**
 * A no-op function that does nothing.
 */
/*@__NO_SIDE_EFFECTS__*/
function noop() { }
/**
 * Create a function that only executes once.
 */
/*@__NO_SIDE_EFFECTS__*/
function once(fn) {
    let called = false;
    let result;
    return function (...args) {
        if (!called) {
            called = true;
            result = fn.apply(this, args);
        }
        return result;
    };
}
/**
 * Wrap an async function to silently catch and ignore errors.
 */
/*@__NO_SIDE_EFFECTS__*/
function silentWrapAsync(fn) {
    return async (...args) => {
        try {
            const result = await fn(...args);
            return result === null ? undefined : result;
        }
        catch { }
        return undefined;
    };
}
/**
 * Execute a function with tail call optimization via trampoline.
 */
/*@__NO_SIDE_EFFECTS__*/
function trampoline(fn) {
    return function (...args) {
        let result = fn.apply(this, args);
        while (typeof result === 'function') {
            result = result();
        }
        return result;
    };
}
