Skip to content

Commit

Permalink
Split Supply.unique into 2 multi's
Browse files Browse the repository at this point in the history
- one doing the explicit expiration case
- one doing the (default) case without expiration
  • Loading branch information
lizmat committed Jan 1, 2020
1 parent 83423ea commit d38cfef
Showing 1 changed file with 40 additions and 37 deletions.
77 changes: 40 additions & 37 deletions src/core.c/Supply.pm6
Expand Up @@ -750,9 +750,9 @@ my class Supply does Awaitable {
SupplyAwaitableHandle.not-ready(self)
}

method unique(Supply:D: :&as, :&with, :$expires) {
supply {
if $expires {
multi method unique(Supply:D: :&as, :&with, :$expires!) {
$expires
?? supply {
if &with and !(&with === &[===]) {
my @seen; # really Mu, but doesn't work in settings
my Mu $target;
Expand Down Expand Up @@ -819,47 +819,50 @@ my class Supply does Awaitable {
}
}
}
else { # !$!expires
if &with and !(&with === &[===]) {
my @seen; # really Mu, but doesn't work in settings
my Mu $target;
if &as {
whenever self -> \val {
$target = &as(val);
if @seen.first({ &with($target,$_) } ) =:= Nil {
@seen.push($target);
emit(val);
}
!! self.unique(:&as, :&with)
}

multi method unique(Supply:D: :&as, :&with) {
supply {
if &with and !(&with === &[===]) {
my @seen; # really Mu, but doesn't work in settings
my Mu $target;
if &as {
whenever self -> \val {
$target = &as(val);
if @seen.first({ &with($target,$_) } ) =:= Nil {
@seen.push($target);
emit(val);
}
}
else {
whenever self -> \val {
if @seen.first({ &with(val,$_) } ) =:= Nil {
@seen.push(val);
emit(val);
}
}
else {
whenever self -> \val {
if @seen.first({ &with(val,$_) } ) =:= Nil {
@seen.push(val);
emit(val);
}
}
}
else {
my $seen := nqp::hash();
my str $target;
if &as {
whenever self -> \val {
$target = nqp::unbox_s(&as(val).WHICH);
unless nqp::existskey($seen, $target) {
nqp::bindkey($seen, $target, 1);
emit(val);
}
}
else {
my $seen := nqp::hash();
my str $target;
if &as {
whenever self -> \val {
$target = nqp::unbox_s(&as(val).WHICH);
unless nqp::existskey($seen, $target) {
nqp::bindkey($seen, $target, 1);
emit(val);
}
}
else {
whenever self -> \val {
$target = nqp::unbox_s(val.WHICH);
unless nqp::existskey($seen, $target) {
nqp::bindkey($seen, $target, 1);
emit(val);
}
}
else {
whenever self -> \val {
$target = nqp::unbox_s(val.WHICH);
unless nqp::existskey($seen, $target) {
nqp::bindkey($seen, $target, 1);
emit(val);
}
}
}
Expand Down

0 comments on commit d38cfef

Please sign in to comment.