Skip to content
Permalink
Browse files

Add support for Pair >>op<< Pair

Since Pairs are generally considered to be 1 element hashes, use the same
logic.  In the situation where if they would be hashes and no matching
keys, an empty hash would be returned.  Since there is no such thing as an
empty Pair, Nil is returned, rather than Nil => Nil.

This commit breaks some spectests because of R#2484.  The next commit works
around that.  Splitting into two separate commits so that the next commit
can simply be reverted once R#2484 is fixed.
  • Loading branch information...
lizmat committed Nov 14, 2018
1 parent d5a751d commit 674a083705d652ae685019e98de54fdef84fe0de
Showing with 35 additions and 0 deletions.
  1. +35 −0 src/core/Hyper.pm6
@@ -176,6 +176,41 @@ class Hyper {
nqp::iscont(left) ?? result.item !! result;
}

# :x >>op<< y
multi method infix(Pair:D \left, \right) {
nqp::p6bindattrinvres(
nqp::clone(left),
Pair,
'$!value',
self.infix(nqp::getattr(left,Pair,'$!value'), right)
)
}

# x >>op<< :y
multi method infix(\left, Pair:D \right) {
nqp::p6bindattrinvres(
nqp::clone(right),
Pair,
'$!value',
self.infix(left, nqp::getattr(right,Pair,'$!value'))
)
}

# :x >>op<< :y
multi method infix(Pair:D \left, Pair:D \right) {
nqp::if(
nqp::getattr(left,Pair,'$!key').WHICH
eq nqp::getattr(right,Pair,'$!key').WHICH,
nqp::p6bindattrinvres(
nqp::clone(left),Pair,'$!value',self.infix(
nqp::getattr(left, Pair,'$!value'),
nqp::getattr(right,Pair,'$!value')
)
),
Nil
)
}

# using an infix on a one element list in a meta op
multi method infix(\object) {
nqp::if(

0 comments on commit 674a083

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