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
optimize partial and partialRight to correctly process rest args #2941
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this change overall, but we need to change the test. I think the one from #2940 that brought this on would be a fine test. We shouldn't really care what happens with the remaining parameters.
var foo = (a, b, c, d, ...rest) => ({ a, b, c, d, rest }); | ||
var f = R.partial(foo, [100, 200]); | ||
eq(f(1, 2, 3, 4), { a: 100, b: 200, c: 1, d: 2, rest: [3, 4] }); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So long as we're supporting ES5, I don't think we can include this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So how should I modify the test, should these test files stay as before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should remove the tests for ...rest
and add one for the version of greet
that inspired #2940. That should show the behavior well enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this way?:
const greet = (salutation, title, firstName, lastName) =>
salutation + ', ' + title + ' ' + firstName + ' ' + lastName + '!';
const greetMsJaneJones = R.partialRight(greet, ['Ms.', 'Jane', 'Jones']);
greetMsJaneJones('Hello', 'Mr.' 'Green'); //=> 'Hello, Ms. Jane Jones!'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exactly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has changed the test as you suggested.
var foo = (a, b, c, d, ...rest) => ({ a, b, c, d, rest }); | ||
var f = R.partialRight(foo, [100, 200]); | ||
eq(f(1, 2, 3, 4), { a: 1, b: 2, c: 100, d: 200, rest: [3, 4] }); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
This looks good to me. Others? @ramda/core? |
@adispring: Another issue that's been dropped. This should go in. Could you resolve the conflicts with the current HEAD? |
Ok, I will resolve the conflict soon. |
4a7c9ac
to
0987d0a
Compare
The conflict has been resolved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@CrossEye Optimize partial and partialRight as you suggested.
related to #2940