Skip to content
Permalink
Browse files

Make Associative <<op>> Associative work a bit better

- 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 bfe2ad63f8ea17cbc11e836b7fcb1c8f35515cbd
Showing with 14 additions and 6 deletions.
  1. +14 −6 src/core/metaops.pm6
@@ -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;
}

0 comments on commit bfe2ad6

Please sign in to comment.
You can’t perform that action at this time.