Open nickstark opened 10 years ago
The naming is a little confusing since it actually returns a function. Usually pluck methods perform the map as well.
This is a tough call because it reads so nicely. Agreed though. We should probably add a suffix such as s
or er
to indicate that the util is a maker/factory.
var names = customers.map(plucks('name'));
I like the pluralizing "plucks". It still reads well.
Another option to be a "to" prefix so it reads like "map to".
var names = customers.map(toProp('name'));
var salary = customer.filter(toProp('fullTime'));
Let's see how well plural and "to" play out for other utils.
Multiple args for deep plucks?
// gets customer.addresses.home.state
var states = customers.map(plucks('addresses', 'home', 'state')).filter(unique());
:+1:
I was thinking that plucks might return an object with multiple keys based on multiple args, but that should probably be a different util.
I was thinking dot notation like customer.addresses
but that's a valid key for an object. I've used json data that has dots in the keys before. For multiple plucks we could use additional args and use array syntax for deep plucks, since arrays are not valid.
var publicInfo = customers.map(plucks('name', 'email', ['address', 'state']));
Might get a little nasty though. A separate method might be justified.
Agreed about dot-notation. I thought about arrays too, but yeah, getting nasty.
Added picks
in #6.
Pluck functionality