DEV Community

Discussion on: Can you help me to improve my Functional Programming skills?

Collapse
 
pradosh987 profile image
Pradosh Gaonkar

Sorry to point out but writing small - small functions is not all together functional. You can try lodash flow to compose camelCaseString using those small functions, that would be functional approach -> , "Composition".

Collapse
 
adancarrasco profile image
Adán Carrasco

Now I see what you meant following the book that Bryce suggested below: mostly-adequate.gitbooks.io/mostly...

Thanks Pradosh!

Collapse
 
adancarrasco profile image
Adán Carrasco

Hi Pradosh - Good to know about lodash and flow, I wasn’t familiar with those! However, in this case as it was an interview challenge I wasn’t allowed to use any third party utility methods, but to solve it by myself. 😅

Collapse
 
pradosh987 profile image
Pradosh Gaonkar

Oh Okay, you know you can implement something like flow, this is just POC and not tested either

export const flow = (methods: Function[]) => {
  return function(...args) {
    return methods
      .slice(1, methods.length)
      .reduce((acc, method) => method(acc), methods[0](args));
  };
};
Thread Thread
 
adancarrasco profile image
Adán Carrasco

This is really cool! Thanks for sharing! 💪🏽💪🏽