/* eslint-disable @typescript-eslint/no-explicit-any */
export default function chainedFunction(...funcs: any[]) {
  return funcs
    .filter((f) => f != null && typeof f === 'function')
    .reduce((acc, f) => {
      if (typeof acc !== 'function') {
        return f;
      }

      return function chainedFunction(this: any, ...args: any[]) {
        acc.apply(this, args);
        f.apply(this, args);
      };
    });
}
