High order function
“The high order function (HOF) is a function that accepts a function as an argument and returns a new function :sweat_smile:” Just read the example, it will directly make more sense to you.
“A curried function is a higher-order function that returns a series of functions each accepting only one argument and only evaluating once we receive our final argument.”
OK this example makes no sense at all. Now, if you start using it for splitting your logic into something simpler and more maintainable, it starts to make a lot of sense:
Finally, the order of arguments are very important. Here we have
baseURL => endpoint => cb for the reason illustrated above. Always remind yourself this simple rule: the order is from most specific to least specific argument.
This one can have its own article or even a series of articles, but I'm sure there are a lot of great resources out there. Basically, it's a function used to compose other functions in a specific order to return to desired output .
This way is much cleaner and more readable than something like
clean(sanitize(lower('My string')));, especially with more complex structure. The order is also very important; in this example, put
lower and your
I will simply disappear.
You can also use the kind-of
As I said, simple concepts, but very helpful to produce any kind of functional code. It will also help you to maintain consistency across your code base if you choose this great paradigm.