Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

array/plucks #1

Open
nickstark opened this issue May 1, 2014 · 9 comments
Open

array/plucks #1

nickstark opened this issue May 1, 2014 · 9 comments
Assignees
Milestone

Comments

@nickstark
Copy link

Pluck functionality

var customers = [ ... ];
var names = customers.map(pluck('name'));
@nickstark
Copy link
Author

The naming is a little confusing since it actually returns a function. Usually pluck methods perform the map as well.

@shannonmoeller
Copy link
Member

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'));

@nickstark
Copy link
Author

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'));

@shannonmoeller
Copy link
Member

Let's see how well plural and "to" play out for other utils.

@nickstark
Copy link
Author

Multiple args for deep plucks?

// gets customer.addresses.home.state
var states = customers.map(plucks('addresses', 'home', 'state')).filter(unique());

@shannonmoeller shannonmoeller changed the title Pluck array/pluck May 2, 2014
@shannonmoeller
Copy link
Member

👍

I was thinking that plucks might return an object with multiple keys based on multiple args, but that should probably be a different util.

@nickstark
Copy link
Author

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.

@shannonmoeller
Copy link
Member

Agreed about dot-notation. I thought about arrays too, but yeah, getting nasty.

@shannonmoeller
Copy link
Member

Added picks in #6.

@shannonmoeller shannonmoeller changed the title array/pluck array/plucks May 2, 2014
@shannonmoeller shannonmoeller added this to the 1.0.0 milestone Jul 8, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants