Skip to content

Instantly share code, notes, and snippets.

@moritz
Created May 5, 2021 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moritz/8ab4e598ec74f2893b76ba3efe4fc44f to your computer and use it in GitHub Desktop.
Save moritz/8ab4e598ec74f2893b76ba3efe4fc44f to your computer and use it in GitHub Desktop.
Change hash keys recursively in Raku #rakulang
my %input = (
'a-b' => [2, { 'b-c' => 'd-x' }]
);
multi change-keys(%input, &changer) {
%input.map(-> $p { changer($p.key) => change-keys($p.value, &changer) }).hash
}
multi change-keys(@input, &changer) {
@input.map(-> $x { change-keys($x, &changer)}).list;
}
multi change-keys($input, &changer) { $input }
say change-keys(%input, { .subst('-', '_') })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment