Last active
September 13, 2022 17:57
-
-
Save jaguart/bd64157bcfa8271ad5bed69a286e0613 to your computer and use it in GitHub Desktop.
ordered hash for JSON::Fast and META6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env raku | |
use v6; | |
use JSON::Fast; | |
class MyHash is Hash { | |
my %w = ( | |
'first' => ' ', | |
'perl' => ' a', | |
'raku' => ' b', | |
'name' => ' c', | |
'auth' => ' d', | |
'version' => ' e', | |
'api' => ' f', | |
'description' => ' g', | |
'source-url' => ' h', | |
'tags' => ' i', | |
'authors' => ' j', | |
'license' => ' k', | |
'provides' => ' l', | |
'depends' => ' m', | |
'resources' => ' n', | |
'last' => '~ ', | |
'final' => '~~', | |
); | |
sub by-weighted-keys { | |
(%w{$^a.key} // $^a.key) cmp (%w{$^b.key} // $^b.key); | |
} | |
method sort( *$keys --> Seq:D ) { | |
return sort( &by-weighted-keys, self.pairs ); | |
} | |
} | |
my %x := MyHash.new: { | |
"perl" => "6.c", | |
"name" => "Vortex::TotalPerspective", | |
"api" => "1", | |
"auth" => "github:SomeAuthor", | |
"version" => "0.0.1", | |
"description" => "Wonderful simulation to get some perspective.", | |
"authors" => [ "Your Name" ], | |
"license" => "Artistic-2.0", | |
"provides" => { | |
"Vortex::TotalPerspective" => "lib/Vortex/TotalPerspective.rakumod" | |
}, | |
"depends" => [ ], | |
"build-depends" => [ ], | |
"test-depends" => [ ], | |
"resources" => [ ], | |
"tags" => [ | |
"Vortex", "Total", "Perspective" | |
], | |
"source-url" => "git=>//github.com/you/Vortex-TotalPerspective.git" | |
}; | |
say to-json( %x, :sorted-keys ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment