-
Notifications
You must be signed in to change notification settings - Fork 83
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
Add a "compose" function #16
Comments
Yes! Great suggestion definitely need a compose method. What do you mean by pipe - does array.map suffice? — On Mon, Nov 24, 2014 at 2:51 PM, kevinb7 notifications@github.com wrote:
|
Maybe "pipe" isn't the right word for what I was thinking of... if you can "compose" two functions, it might be useful to compose an array of functions into a single function, e.g. |
Yup, I believe reduceRight in combination with a compose does what you want — On Mon, Nov 24, 2014 at 3:30 PM, kevinb7 notifications@github.com wrote:
|
Some quick thoughts on
the results of these two operations are identical
|
@jfsiii Why would you reverse the arguments in function composeLeft() {
var fns = Array.prototype.slice.call(arguments);
return function () {
var args = arguments;
fns.forEach(function(fn){
args = [fn.apply(this, args)];
});
return args[0];
};
} I also have a question I hope could be answered. What is the benefit/purpose of applying the context |
@JakeChampion The functions were just examples to demonstrate their usefulness. The specific implementation can be discussed in a PR or elsewhere. You're right that I could have omitted the argument reversal and just changed the order the functions were applied. However, that still means I don't know the root of your last question. Do you think a value other than |
These look like good suggestions guys! Thanks will definitely be adding |
@tjmehta I'm glad to submit a PR. Patches welcome? :) |
I see, what I meant is that |
Added #30 |
Great library. "compose" would be good.
Maybe "pipe" too so that you send values through a series of functions.The text was updated successfully, but these errors were encountered: