Skip to content

Commit

Permalink
Make Associative <<op>> Associative work a bit better
Browse files Browse the repository at this point in the history
- no longer throws if left side is an immutable type like Map
- directly call STORE rather than going through the assign magic
- call STORE with :INITIALIZE (so that it can work on immutable types)

This does *not* fix the issue with objects hashes and QuantHashes of the
keys are not strings.
  • Loading branch information
lizmat committed Nov 2, 2018
1 parent 7ee1f3c commit bfe2ad6
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/core/metaops.pm6
Expand Up @@ -540,22 +540,30 @@ multi sub HYPER(&op, Associative:D \left, Associative:D \right, :$dwim-left, :$d
%keyset{$_} = 1 for right.keys;
}
my @keys = %keyset.keys;
my \result := left.WHAT.new;
result = quietly @keys Z=> HYPER(&op, left{@keys}, right{@keys}, :$dwim-left, :$dwim-right);
my \result := left.WHAT.new.STORE(
(quietly @keys Z=>
HYPER(&op,left{@keys},right{@keys},:$dwim-left,:$dwim-right)
),
:INITIALIZE
);
nqp::iscont(left) ?? result.item !! result;
}

multi sub HYPER(&op, Associative:D \left, \right, :$dwim-left, :$dwim-right) {
my @keys = left.keys;
my \result := left.WHAT.new;
result = @keys Z=> HYPER(&op, left{@keys}, right, :$dwim-left, :$dwim-right);
my \result := left.WHAT.new.STORE(
(@keys Z=> HYPER(&op,left{@keys},right,:$dwim-left,:$dwim-right)),
:INITIALIZE
);
nqp::iscont(left) ?? result.item !! result;
}

multi sub HYPER(&op, \left, Associative:D \right, :$dwim-left, :$dwim-right) {
my @keys = right.keys;
my \result := right.WHAT.new;
result = @keys Z=> HYPER(&op, left, right{@keys}, :$dwim-left, :$dwim-right);
my \result := right.WHAT.new.STORE(
(@keys Z=> HYPER(&op,left,right{@keys},:$dwim-left,:$dwim-right)),
:INITIALIZE
);
nqp::iscont(right) ?? result.item !! result;
}

Expand Down

0 comments on commit bfe2ad6

Please sign in to comment.