Skip to content

Implement std.objectValues and std.objectValuesAll#858

Merged
sbarzowski merged 1 commit intogoogle:masterfrom
tragiclifestories:objectvalues
Oct 23, 2020
Merged

Implement std.objectValues and std.objectValuesAll#858
sbarzowski merged 1 commit intogoogle:masterfrom
tragiclifestories:objectvalues

Conversation

@tragiclifestories
Copy link
Copy Markdown

Hello friends!

This PR adds two helper functions for extracting an array of values from an object. This was not impossible before (hence the implementations are in jsonnet), but I think it is worth having a 'first class' implementation - for further evidence, it is a very common feature of data transformation libraries.

It was mentioned in this comment.

@google-cla google-cla bot added the cla: yes label Oct 23, 2020
If an external variable with the given name was defined, return its string value. Otherwise, raise an error.
</p>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sorry about this noise - I have an vim trigger thing that deletes trailing whitespace ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please don't edit this file manually. Here are the instructions for updating stdlib docs: https://github.com/google/jsonnet#locally-serving-the-website.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ah, that makes a lot more sense - updated.

Copy link
Copy Markdown
Contributor

@sbarzowski sbarzowski left a comment

Choose a reason for hiding this comment

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

Thanks! This is a good addition to the standard library.

If an external variable with the given name was defined, return its string value. Otherwise, raise an error.
</p>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please don't edit this file manually. Here are the instructions for updating stdlib docs: https://github.com/google/jsonnet#locally-serving-the-website.

assert std.isNumber(from) : 'substr second parameter should be a string, got ' + std.type(from);
assert std.isNumber(len) : 'substr third parameter should be a string, got ' + std.type(len);
assert len >=0 : 'substr third parameter should be greater than zero, got ' + len;
assert len >= 0 : 'substr third parameter should be greater than zero, got ' + len;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

These changes are also all autoformatting but they look like good changes? I can rebase and just take the actual stuff I added if you want.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, it looks like our own auto-formatting. Ideally that would be a separate commit, but that's not a big deal.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants