aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2017-04-25 09:44:36 +0200
committerPatrick Spek <p.spek@tyil.nl>2017-04-25 09:44:36 +0200
commitcb5db41329c1aab1cb56d7a3e381c53d668af844 (patch)
treed5e0eb0c229ab9431bed0c8e91d25969ede5a2f5
parent8044c52208ded8b58179b7f52a93ef3009665226 (diff)
Reformat code to my liking
-rw-r--r--lib/mergehash.pm631
1 files changed, 19 insertions, 12 deletions
diff --git a/lib/mergehash.pm6 b/lib/mergehash.pm6
index db3d016..b24f25d 100644
--- a/lib/mergehash.pm6
+++ b/lib/mergehash.pm6
@@ -1,5 +1,10 @@
+#! /usr/bin/env false
+
+use v6.c;
use MONKEY;
-augment class Hash {
+
+augment class Hash
+{
#| Merges a second hash into the hash the method is called on. Hash given as
#| the argument is not modified.
#| Traverses the full tree, replacing items in the original hash with the
@@ -10,35 +15,37 @@ augment class Hash {
#| Use :no-append-array to replace arrays and positionals instead, which will
#| also retain the original type and not convert to an Array
#|
- method merge (%b; Bool:D :$no-append-array = False) {
+ method merge (%b; Bool:D :$no-append-array = False)
+ {
hashmerge self, %b, :$no-append-array;
}
- sub hashmerge (%merge-into, %merge-source, Bool:D :$no-append-array) {
+
+ sub hashmerge (%merge-into, %merge-source, Bool:D :$no-append-array)
+ {
for %merge-source.keys -> $key {
if %merge-into{$key}:exists {
if %merge-source{$key} ~~ Hash {
hashmerge %merge-into{$key}, %merge-source{$key}, :$no-append-array;
- }
- elsif %merge-source{$key} ~~ Positional {
+ } elsif %merge-source{$key} ~~ Positional {
if $no-append-array {
%merge-into{$key} = %merge-source{$key};
- }
- else {
+ } else {
my @a;
+
@a.push: $_ for %merge-into{$key}.list;
@a.push: $_ for %merge-source{$key}.list;
+
%merge-into{$key} = @a;
}
- }
- # Non-positionals, so strings or Bools or whatever
- else {
+ } else {
+ # Non-positionals, so strings or Bools or whatever
%merge-into{$key} = %merge-source{$key};
}
- }
- else {
+ } else {
%merge-into{$key} = %merge-source{$key};
}
}
+
%merge-into;
}
}