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

In README show how to get "to-json" keys sorted like "%h.keys.sort({.Numeric)" #90

Open
tbrowder opened this issue Jul 12, 2023 · 1 comment

Comments

@tbrowder
Copy link

No description provided.

@tbrowder
Copy link
Author

tbrowder commented Jul 12, 2023

This works (as suggested by [Coke]): define a sub suitable for the key types expected:

sub my-sort($a, $b) { $a.key cmp $b.key }
my $jstr = to-json %h, :pretty, :sorted-keys(&my-sort);

If multiple key types are expected, then the sub should use elsif or when to define what the user wants when a key pair is not directly comparable. For example, I used this sub for mixed Str and Int types:

TO BE COMPLETE A BIT LATER (when I get back to a real computer)

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

No branches or pull requests

1 participant