Elegant patterns in modern JavaScript: RORO
Bill Sourour

Hey Bill.

First of all, thanks for reminding me how much I love piping functions and hate passing params. You will not believe how many times I have seen and implemented this pattern, yet somehow i always got myself passing extra variables here and there and passing dependencies as well so that the code will be more testable and then kaboom- you wanted clean independent functions, you got a mess instead. What I am trying to say is-it is really important to enforce this pattern if you decide using it, and now with rest params, destructuring and default values it is cleaner and easier to do. What i have learned and still learning to do is always keep params to a minimum, and better yet, only one.

Second, nice trick with the default error handler, i used checker if functions or libraries like superstruct etc. Really clean. I will definitely add it to my arsenal.

A few thing to note:

  • Destructuring does a shallow copy, complex data types( array, object ) get copied by reference.
  • Save user to db could be written without the func surrounding it. It is callled pointfree style. Because you wrap a function that expects a param and return another function which expects the same param, you can omit the surrounding function.


Like what you read? Give Yuri Homyakov a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.