fn.js
fn.js copied to clipboard
Function modifiers to take function as last argument
By default function should be passed as last argument. Work out how to setup changelog
Switch argument order of throttle arguments
There are further functions such as apply that also break this rule
I'm confused as to why you would want to switch all methods to have function be last argument. Making methods take their data as the last argument is what makes methods composable, and is the very reason why underscore/lodash is unsuitable for functional programming. Maybe I am mistaken on the intention of this issue?
I think it depends how you are composing, I think. If all functions are curried then having a function as last args means you can do the following.
var throttleToMyLimit = throttle(100);
var logIt = throttleToMyLimit(console.log);
Although I think it might make sense to have a function with the arguments reversed so throttle and throttleTo could exist like delay and delayFor
This is very different from the direction we took with Ramda, and I'm trying to see the advantage.
To me the order is straightforward: from the parameter least likely to change to the one most likely to change. A simple example is map. This seems a much more likely requirement:
var squareAll = map(square) ;
squareAll([1, 2, 3]): //=> [1, 4, 9]
squareAll([4, 5, 6]); //=> [16, 25, 36]
than does this:
var map123 = map ([1, 2, 3]);
map123(square) ; //=> [1, 4, 9]
map123(add(1)); //=> [2, 3, 4]
So the transformation function should be the first parameter and the list of values second. And most every function works this way.
@CrossEye I agree with what you are saying there.
I think the same logic applies(although the terms might get more confusing) with functions on functions.
If you have a library of higer-order functions who's purpose is to modify other raw functions then the raw function to be modified should be supplied as the last parameter.
So in the example of throttle it make sense to me to be throttle(delay, rawFunction)
And use of the curried form acts as a factory to produce preconfigued throttling functions
var throttle100 = throttle(100);
throttle100(rawFunction);
I think I was reacting more to the title than to your example. throttle seems either ambiguous to me or perhaps slightly biased toward function-last. That's reasonable. From the title, I thought you meant to change to function-last everywhere.
Carry on. Don't mind me. :smile: