For those of you unfamiliar with partial function application, it's a good way to replace many classes that consist of nothing other than a single "do the work" method and a constructor or setters for the configuration/dependencies with a single function.
You put the configuration / dependency parameter(s) first, and the more "volatile" parameter(s) last. Rather than having a constructor call, you partially apply the things you want pre-bound (config, deps) to create a new shorter function that acts as the "do it!" method.
E.g. - write a function to send emails. Put the "reply to" parameters first. Partially apply that data. Use the resulting function to send emails to specific people. Bind on the distribution list name argument. Use that function to send alerts to those recipients. Bind on the content of an alert. Use that to send an alert when needed, without having to come up with any of the input, just the 0-argument function. Overloading, alternate constructors, subclasses??? Screw that. As long as the parameter order is reasonable (least to most volatile), there is seldom anything to be "refactored"
"Currying" just means that you apply a single argument at a time, until you get down to an "arity 1" function, after which the final argument runs the original function with the last remaining argument, rather than returning an "arity 0" function. Here is an example library that does A LOT of currying: http://ramdajs.com/docs/
If I apply/bind a function to my higher order function, is that dependency injection, or subclassing? Who cares.
I like arity 0 functions. They make nice event handlers.
I have been gradually converting to Javascript for the last 8 years. My paradigm has definitely shifted. I know how miserable static OOP is, and won't be going to my grave not knowing :-) (here's the quote: https://www.facebook.com/groups/nodejsis/permalink/142940052...)
I suppose this is orthogonal to compile time types, but I had to write my own utility to support PFA "decoration" of functions. It of course knows nothing about the number or type of arguments in the original function. (I usually write JSDoc comments about resulting intermediate functions if they leave the nest)
For TS to do this, the compiler would need to supply the "apply"/"bind" feature and track that a function goes in, and the list of argument types, so it can check what is applied and track the types of any remaining arguments. Doable, but if it's not built into the compiler, I have to start running a transpile process that buys very little for much of my code.
You put the configuration / dependency parameter(s) first, and the more "volatile" parameter(s) last. Rather than having a constructor call, you partially apply the things you want pre-bound (config, deps) to create a new shorter function that acts as the "do it!" method.
E.g. - write a function to send emails. Put the "reply to" parameters first. Partially apply that data. Use the resulting function to send emails to specific people. Bind on the distribution list name argument. Use that function to send alerts to those recipients. Bind on the content of an alert. Use that to send an alert when needed, without having to come up with any of the input, just the 0-argument function. Overloading, alternate constructors, subclasses??? Screw that. As long as the parameter order is reasonable (least to most volatile), there is seldom anything to be "refactored"
"Currying" just means that you apply a single argument at a time, until you get down to an "arity 1" function, after which the final argument runs the original function with the last remaining argument, rather than returning an "arity 0" function. Here is an example library that does A LOT of currying: http://ramdajs.com/docs/
If I apply/bind a function to my higher order function, is that dependency injection, or subclassing? Who cares.
I like arity 0 functions. They make nice event handlers.
I have been gradually converting to Javascript for the last 8 years. My paradigm has definitely shifted. I know how miserable static OOP is, and won't be going to my grave not knowing :-) (here's the quote: https://www.facebook.com/groups/nodejsis/permalink/142940052...)