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 ES2024 Map.groupBy #1454

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

robik
Copy link
Contributor

@robik robik commented Jun 28, 2024

Summary

This PR implements EcmaScript 2024 Map.groupBy

Test Plan

Added tests.

>> Map.groupBy([1, 2, 3, 4, 5, 6, 7], function(key) { return key % 2; })
Map { "1" => [ 1, 3, 5, 7, [length]: 4 ], "0" => [ 2, 4, 6, [length]: 3 ] }

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Jun 28, 2024
@facebook-github-bot
Copy link
Contributor

@lavenzg has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@avp avp left a comment

Choose a reason for hiding this comment

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

Thanks for adding this!

groupKey = runtime.makeHandle(std::move(*keyRes));

// make it a property key
auto propertyKeyRes = toPropertyKey(runtime, groupKey);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we're supposed to call GroupBy with "COLLECTION" mode, so we shouldn't be converting to PropertyKey here.

print(JSON.stringify(map.get('underage')))
//CHECK-NEXT: [{"name":"Peter","age":15}]
print(JSON.stringify(map.get('adult')))
//CHECK-NEXT: [{"name":"Mike","age":20},{"name":"John","age":22}]
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also have a couple tests for non-string/int keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants