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

optional parameter for predicate on _.unique #2368

Closed
wants to merge 3 commits into from

Conversation

dperrymorrow
Copy link

this allows for using custom matcher function for comparison
defaults to _.isEqual for comparison #2311

added a _.uniqueWith function as discussed, also added _.includeWith as a method to detect if an Array or Collection has an item passing a method. This will be useful if we implement the other methods discussed in the thread as well.

this allows for using custom matcher function for comparison
defaults to _.isEqual jashkenas#2311
@jdalton
Copy link
Contributor

jdalton commented Dec 1, 2015

I think this would have a better chance of landing without bundling it with includesWith at the moment because that raises questions about how to handle fromIndex and things which are a side track to _.uniqWith.

this is an additional last predicate parameter
rather than defining new methods for using equality
comparison other than ===
@dperrymorrow
Copy link
Author

Ive updated this to use a predicate parameter #2311
let me know how you think this works.

_.uniq = _.unique = function(array, isSorted, iteratee, context, predicate) {
//...

if (!_.isBoolean(isSorted)) {
context = iteratee;
iteratee = isSorted;
isSorted = false;
predicate = _.isNull(predicate) ? context : predicate;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

predicate == null && _.isFunction(context) ? ...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that would be better to ensure that context is a function before assigning it to predicate. thanks.

using optimizeCb for binding
making sure that context is a function before
assigning to predicate in overloading of unique
@dperrymorrow
Copy link
Author

made the suggested changes, thanks @megawac

@dperrymorrow dperrymorrow changed the title adding includeWith, and uniqueWith functions optional parameter for predicate on _.unique Dec 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants