p5-type-tiny
p5-type-tiny copied to clipboard
Provide a facility for combining two `Dict` types
Extracting this from #110.
Basically a shortcut for:
my $combined = Dict[
$dict1->parameters->@*,
$dict2->parameters->@*,
];
This could be a function, a method, an overload, etc. Just something to make it easier.
Complications:
- If neither
$dict1nor$dict2have a slurpy, neither should$combined. If one of them has a slurpy,$combinedshould inherit it. If$dict1and$dict2have slurpies typedHashRef[$s1]andHashRef[$s2], then$combinedshould have a slurpy typed$s1 | $s2. Otherwise$combinedshould haveSlurpy[Any]. - option to demote
$dict2's keys to being optional in$combined?
Further complication… what about this?
my $dict1 = Dict[ foo => HashRef ];
my $dict2 = Dict[ foo => ArrayRef ];
my $combined = combine( $dict1, $dict2 );
What values should $combined allow for foo? HashRef | ArrayRef even though an arrayref will confuse consumers of $dict1 and a hashref will confuse consumers of $dict2? HashRef & ArrayRef even though that matches nothing?