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

array/masks #6

Open
shannonmoeller opened this issue May 2, 2014 · 5 comments
Open

array/masks #6

shannonmoeller opened this issue May 2, 2014 · 5 comments

Comments

@shannonmoeller
Copy link
Member

Gets multiple values from items in an array.

var customers = [ ... ];
var names = customers.map(picks('firstName', 'lastName'));
@shannonmoeller
Copy link
Member Author

@nickstark
Copy link

Just an idea, I like the name mask for this, but it also makes a difference how it would work functionally if a value doesn't exist.

Intuitively, I think they do slightly different things.

var customers = [
    { name: 'jeff', parkingSpace: 22 },
    { name: 'mike' }
];
var pickedSpaces = customers.map(picks('parkingSpace')); // [{parkingSpace:22},{parkingSpace:undefined}]
var maskedSpaces = customers.map(masks('parkingSpace')); // [{parkingSpace:22},{}]

Thoughts?

@shannonmoeller
Copy link
Member Author

The only difference between those two results would be the resulting value of key in obj and obj.hasOwnProperty(key). I think we should pass through values, if any, unmodified, so that the resulting object looks as similar to the original as possible:

{ name: 'jeff', parkingSpace: 22 } // -> { parkingSpace: 22 }
{ name: 'jeff', parkingSpace: undefined } // -> { parkingSpace: undefined }
{ name: 'jeff' } // -> { }

@nickstark
Copy link

I think that's the better behavior, too. So going along with that, I like the name masks better. I would confuse picks with plucks all the time. Then we'd have a slice/splice situation.

@shannonmoeller
Copy link
Member Author

Works for me. I was just aping mout (http://moutjs.com/docs/v0.9/object.html#pick).

@nickstark nickstark changed the title array/picks array/masks May 6, 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