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

__filter for associative arrays #19

Open
yankeeinlondon opened this issue Oct 28, 2012 · 1 comment
Open

__filter for associative arrays #19

yankeeinlondon opened this issue Oct 28, 2012 · 1 comment

Comments

@yankeeinlondon
Copy link

I would love to see filter() be able to operate on associative arrays. There are so many cases you have a list of name-value pairs and you want to reduce this to a subset which is defined by a list of either values to exclude (black-list approach) or a list of to include only a list (white-list approach). I had hoped to have something like:

$start = array ( "one" => "monkey" , "two" => "donkey" , "three" => "beetle" );
$filter = array ( "two", "three" );

$list = ___::filter( $start, function ($value,$key) {
return in_array( $key , $filter );
});

I'd be interested to know if this is better achieved a different way (as I'm still relatively new to underscore) or whether this would be seen as a worthwhile extension to the functionality if I were to fork it off.

@KyleAMathews
Copy link

I just was bit by this. Coming from underscore.js I assumed this would be built-in already.

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

2 participants