~tyil/raku-hash-merge

54570330b51345438abd6f58bb3ff6f40818e504 — Patrick Spek 4 years ago 5209a8c
Bring the other sub in line too
1 files changed, 7 insertions(+), 5 deletions(-)

M lib/Hash/Merge.pm6
M lib/Hash/Merge.pm6 => lib/Hash/Merge.pm6 +7 -5
@@ 6,19 6,21 @@ unit module Hash::Merge;

#| Merge any number of Hashes together.
sub merge-hashes (
	*@hashes, #= Hashes to merge together
	#| Any number of Hashes to merge together.
	*@hashes,

	--> Hash
) is export {
	my %merge-into = @hashes.shift;
	my %result = @hashes.shift;

	# Nothing to do if we only got 1 argument
	return %merge-into unless @hashes.elems;
	return %result unless @hashes.elems;

	for ^@hashes.elems {
		%merge-into = merge-hash(%merge-into, @hashes.shift);
		%result = merge-hash(%result, @hashes.shift);
	}

	%merge-into;
	%result;
}

#| Merge two hashes together.