/**
 * Only ever execute the supplied function once. Subsequent calls
 * will return the value from the first invocation.
 */
export function once<T extends (...args: unknown[]) => unknown>(method: T): T {
  let executed = false;
  let returnValue: unknown;

  return function onceInner(this: unknown, ...args: unknown[]) {
    if (!executed) {
      executed = true;
      returnValue = method.apply(this, args);
    }
    return returnValue;
  } as T;
}
