Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function modifiers to take function as last argument #25

Open
CrowdHailer opened this issue Jan 9, 2016 · 8 comments
Open

Function modifiers to take function as last argument #25

CrowdHailer opened this issue Jan 9, 2016 · 8 comments

Comments

@CrowdHailer
Copy link
Owner

By default function should be passed as last argument.
Work out how to setup changelog

@CrowdHailer CrowdHailer changed the title Switch argument order of throttle arguments Argument order to take function last Jan 10, 2016
@CrowdHailer
Copy link
Owner Author

Switch argument order of throttle arguments

@CrowdHailer
Copy link
Owner Author

There are further functions such as apply that also break this rule

@eliperelman
Copy link
Collaborator

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?

@CrowdHailer
Copy link
Owner Author

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);

@CrowdHailer
Copy link
Owner Author

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

@CrossEye
Copy link

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.

@CrowdHailer
Copy link
Owner Author

@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);

@CrossEye
Copy link

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. 😄

@CrowdHailer CrowdHailer changed the title Argument order to take function last Function modifiers to take function as last argument Jan 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants