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

Feature suggestion - projection over dataset #7

Open
hoegrammer opened this issue Sep 16, 2016 · 1 comment
Open

Feature suggestion - projection over dataset #7

hoegrammer opened this issue Sep 16, 2016 · 1 comment
Assignees

Comments

@hoegrammer
Copy link

hoegrammer commented Sep 16, 2016

Not an issue, but what do you think about including a "project" function to return a projection over a dataset, something like this:

projectAddress = project(["house", "street"]);
data = [{house: 24, street: "Main", name: "John"}, {house: 35, street: "Park", name: "Phil"}]
projectAddress(data)
// [ { house: 24, street: 'Main' }, { house: 35, street: 'Park' } ]

Here's a quick implementation:

projectOne = fields => obj => fields.reduce((x,y) => {x[y] = obj[y]; return x}, {})
project = fields => fjs.map(projectOne(fields))

@jakubbarczyk
Copy link
Contributor

As far as I recall, all major utility and/or functional libraries have similar functions. Names vary, "pick", "pluck", but the concept is projection.

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

No branches or pull requests

3 participants