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

Add objectKeysValues, objectKeysValuesAll #1062

Merged
merged 1 commit into from
Apr 13, 2023

Conversation

zephyros-dev
Copy link
Contributor

@zephyros-dev zephyros-dev commented Apr 9, 2023

This PR adds two helper functions for extracting an array of objects with keys and values from an object. It's a simple function but I think it's worth putting into the stdlib given its appearance in numerous feature requests #865, #543

@google-cla
Copy link

google-cla bot commented Apr 9, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@sparkprime sparkprime merged commit f071376 into google:master Apr 13, 2023
@zephyros-dev zephyros-dev deleted the objectKeysValues branch June 22, 2023 09:59
@KetchupBomb
Copy link
Contributor

@zephyros-dev, this PR adds a bit of naming complexity to the std library. There are two existing functions:

  • std.objectFields()
  • std.objectValues()

Your addition of:

  • std.objectKeysValues()

introduces the term "keys" into the std library where the convention refers to them as "fields".

It's minor, but I appreciate consistency. Do you have opinions on changing it to:

  • std.objectFieldsValues()

@zephyros-dev
Copy link
Contributor Author

zephyros-dev commented Jul 10, 2023

I also thought about naming it with objectFieldsValues when I first made the PR, but I changed my mind after looking through the feature requests #865 and #543. In there I see that the main terms used by both the maintainers and the commenters are keys and values, and personally I do prefer the terms since it is also used in popular programming languages like Javascript or Python.
I do think the naming should be more consistent, but changing the function names to objectFieldsValues means modifying the signature of the return object to {'field': 'foo', 'value': 'bar'} if we want to be consistent to the function name (Right now it's {'key': 'foo', 'value': 'bar'}). What I think could be done instead is to add an alias for the std.objectFields() as std.objectKeys() since the return value (a list of string) doesn't depend on the function name.

@KetchupBomb
Copy link
Contributor

It's probably too late to change in either direction, but I think this is a miss for better standardization. I agree that "field" is strange when everyone else is accustomed to "key", but adding variance is worse IMO. Though there are more mentions of "key" in the std lib than "field". 🤔

I suppose my practical worries are mitigated anyway since I maintain my own form of a standard library and I can just hide/rename std.objectKeysValues().

Thanks for your time.

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.

3 participants