/**
 * Maps arguments of the same type to a flat array, excluding null and undefined values
 * 
 * @param {T | T[] | null | undefined} args 
 * @returns {T[]}
 */
export const arrayify = <T extends unknown>(...args: (T | T[] | null | undefined)[]): T[] => {
  return args
    .flatMap(arg => arg ?? [])
    .filter(arg => arg !== null && arg !== undefined);
};

/**
 * Gets the first value of an array, or the value itself if it's not an array
 *
 * @param {T | T[]} arg 
 * @returns {T}
 */
export const getFirstOrValue = <T extends unknown>(arg: T | T[] = []) => (
  Array.isArray(arg) ? arg[0] : arg
);
