overloading fun

by Gerald Gillespie

JavaScript

const modules = {
  'N/log': {
    debug: (x => console.log({
      x
    }))
  }
};

const getReadyFn = ([first,...none])=>
(cb)=>{
if( typeof cb !== 'function') return first;
else return cb(first); 
}


const repeater = (paths, fnOrNot, ...remainder) => {
  if (Array.isArray(paths) && typeof fnOrNot === 'function') {
    return fnOrNot(...(paths.map(path => modules[path])));
  }
  
  if(Array.isArray(paths) && Reflect.has(paths,'raw')){
   return getReadyFn(paths.map(path => modules[path])); 
  }
  
};


const x = repeater(['N/log'], (Nlog) =>
  Nlog.debug('hi'));
  
  
const y = repeater`N/log`();

console.log({y});

const z = repeater`N/log`((Nlog)=>{
    Nlog.debug('bye');
    return 'foo';
});

const a = repeater`aldsf`()

console.log({a})