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

feat: add improved prune() function #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Duologic
Copy link
Member

It often comes up that std.prune() is recursive, although the documentation states that it is, this still catches people off guard.

The function introduced here provides options to disable recursion and only prune null values.

@Duologic Duologic marked this pull request as ready for review March 15, 2024 10:02
@Duologic Duologic requested a review from jdbaldry March 15, 2024 10:02
'#': d.pkg(
name='reflect',
url='github.com/jsonnet-libs/xtd/reflect.libsonnet',
help='`reflect` implements helper functions for processing json data.',
Copy link

Choose a reason for hiding this comment

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

nit:

Suggested change
help='`reflect` implements helper functions for processing json data.',
help='`reflect` implements helper functions for processing JSON data.',

else true;
local doRecursion(x) =
if recurse
then self.prune(x, only_null=only_null)
Copy link

Choose a reason for hiding this comment

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

nit: I think it's more common to see that the recursive call uses the exact same arguments as the initial call because it explicitly demonstrates that the recursive call is gonna continue the same behavior.

Suggested change
then self.prune(x, only_null=only_null)
then self.prune(x, recurse, only_null)

Copy link

Choose a reason for hiding this comment

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

For completeness, I think that all primitives need to exist in the test objects or at least zero-length arrays to demonstrate that the same std.prune behavior is preserved.

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.

2 participants