Skip to content

Commit

Permalink
Make sure immutable structures also work with Associatives
Browse files Browse the repository at this point in the history
- such as: dd (a => 42, b => 666).Map >>+>> 2  # Map.new((:a(44),:b(668)))
- alas, we need customized Associative handling for QuantHashes
  - .STORE expects Pairs for QuantHashes
  • Loading branch information
lizmat committed Nov 11, 2018
1 parent 63ae9dc commit fa5215b
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/core/Hyper.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ class Hyper {
# %x >>op<< y
multi method infix(Associative:D \left, \right --> Associative:D) {
my @keys is List = left.keys;
my \result := left.WHAT.new.STORE(
my \result := nqp::create(left.WHAT).STORE(
Seq.new(
Rakudo::Iterator.RoundrobinIterablesFlat(
(@keys, self.infix(left{@keys}, right))
)
)
),
:INITIALIZE
);
nqp::iscont(left) ?? result.item !! result;
}
Expand All @@ -60,12 +61,13 @@ class Hyper {
# x >>op<< %y
multi method infix(\left, Associative:D \right --> Associative:D) {
my @keys is List = right.keys;
my \result := right.WHAT.new.STORE(
my \result := nqp::create(right.WHAT).STORE(
Seq.new(
Rakudo::Iterator.RoundrobinIterablesFlat(
(@keys, self.infix(left, right{@keys}))
)
)
),
:INITIALIZE
);
nqp::iscont(right) ?? result.item !! result;
}
Expand Down Expand Up @@ -288,12 +290,13 @@ class Hyper {
nqp::p6bindattrinvres(nqp::create(Map),Map,'$!storage',$keys).keys;

# run with the left/right values
my \result := left.WHAT.new.STORE(
my \result := nqp::create(left.WHAT).STORE(
Seq.new(
Rakudo::Iterator.RoundrobinIterablesFlat(
(@keys, quietly self.infix(left{@keys}, right{@keys}))
)
)
),
:INITIALIZE
);
nqp::iscont(left) ?? result.item !! result;
}
Expand All @@ -316,12 +319,13 @@ class Hyper {
nqp::p6bindattrinvres(nqp::create(Map),Map,'$!storage',$keys).values;

# run with the left/right values
my \result := left.WHAT.new.STORE(
my \result := nqp::create(left.WHAT).STORE(
Seq.new(
Rakudo::Iterator.RoundrobinIterablesFlat(
(@keys, quietly self.infix(left{@keys}, right{$keys}))
)
)
),
:INITIALIZE
);
nqp::iscont(left) ?? result.item !! result;
}
Expand Down

0 comments on commit fa5215b

Please sign in to comment.