export type Factory = (...args: Args) => Value; /** Decorate the factory selected at the time this function is called. */ export function decorateCurrentFactory( current: Factory | undefined, fallback: Factory, decorate: (value: Value, ...args: Args) => Value, ): Factory { const base = current ?? fallback; return (...args: Args) => decorate(base(...args), ...args); }