p5-type-tiny icon indicating copy to clipboard operation
p5-type-tiny copied to clipboard

Provide a facility for combining two `Dict` types

Open tobyink opened this issue 3 years ago • 1 comments

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 $dict1 nor $dict2 have a slurpy, neither should $combined. If one of them has a slurpy, $combined should inherit it. If $dict1 and $dict2 have slurpies typed HashRef[$s1] and HashRef[$s2], then $combined should have a slurpy typed $s1 | $s2. Otherwise $combined should have Slurpy[Any].
  • option to demote $dict2's keys to being optional in $combined?

tobyink avatar Sep 08 '22 08:09 tobyink

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?

tobyink avatar Sep 08 '22 08:09 tobyink