import { invoke } from './invoke.ts';

/**
 * Creates a function that invokes the method at a given path of `object` with the provided arguments.
 *
 * @param object - The object to query.
 * @param args - The arguments to invoke the method with.
 * @returns Returns a new function that takes a path and invokes the method at `path` with `args`.
 *
 * @example
 * const object = {
 *  a: {
 *   b: function (x, y) {
 *    return x + y;
 *    }
 *   }
 * };
 *
 * const add = methodOf(object, 1, 2);
 * console.log(add('a.b')); // => 3
 */
export function methodOf(object: object, ...args: any[]): (path: PropertyKey | readonly PropertyKey[]) => any {
  return function (path: PropertyKey | readonly PropertyKey[]) {
    return invoke(object, path, args);
  };
}
