Skip to content
New issue

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

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

Already on GitHub? # to your account

Feature request: _.matches accepting an array as the argument, or multiple arguments #2008

Closed
afanasy opened this issue Jan 14, 2015 · 3 comments

Comments

@afanasy
Copy link

afanasy commented Jan 14, 2015

So it's possible to filter by multiple values of the same key:

_.matches([{name: 'Bob'}, {name: 'Alice'}])
//matches both {name: 'Bob'} and {name: 'Alice'}

//and this syntax would be nice to have too :)
_.matches({name: 'Bob'}, {name: 'Alice'})
//matches both {name: 'Bob'} and {name: 'Alice'}
@megawac
Copy link
Collaborator

megawac commented Jan 19, 2015

I would sooner have a anyPass and allPass which call each function in an array with provided arguments

Then we could do

var isBobOrAlice = _.partial(_.anyPass, _.map([{name: 'Bob'}, {name: 'Alice'}], _.matches));

isBobOrAlice({name: 'Bob'})

@afanasy
Copy link
Author

afanasy commented Jan 21, 2015

This looks good too, but I wanted to use _.where in the same manner:

_.where(person, [{name: 'Bob'}, {name: 'Alice'}])

returns array with Bob and Alice
and the new syntax is backward compatible as far as I can see, it just adds the special handling case if argument is an array

@jashkenas
Copy link
Owner

Yeah, anyPass and allPass would be better than this. If you want boolean logic, just use it!

_.matches(a) or _.matches(b)

_.matches(a) and _.matches(b) and not _.matches(c)

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants