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

Implement collections/associateBy #1071

Merged
merged 5 commits into from
Jul 31, 2021
Merged

Implement collections/associateBy #1071

merged 5 commits into from
Jul 31, 2021

Conversation

LionC
Copy link
Contributor

@LionC LionC commented Jul 27, 2021

This adds an associateBy function to the collections module.

associateBy transforms an array into a Record, often used to conveniently access it by key instead of iterating via e.g. .find() afterwards:

const users = [
    { id: 'a2e', userName: 'Anna' },
    { id: '5f8', userName: 'Arnold' },
    { id: 'd2c', userName: 'Kim' },
]

const usersById = associateBy(users, it => it.id)
const someId = 'a23'
const user = usersById[someId]

associateBy was part of the original proposal (see #1065 and its links). In the discussions around it and following the merge of the initial set of functions, it seemed that there are no strong opinions against it, so I posted this PR.

@kt3k kt3k mentioned this pull request Jul 28, 2021
26 tasks
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LionC Nice work! LGTM

@kt3k kt3k merged commit f8b46d0 into denoland:main Jul 31, 2021
@LionC LionC deleted the associate-by branch July 31, 2021 19:58
@LionC LionC mentioned this pull request Aug 27, 2021
44 tasks
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

Successfully merging this pull request may close these issues.

None yet

2 participants