Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Streamline "uniq" and "squish", suggested by jnthn++
  • Loading branch information
lizmat committed Jul 3, 2013
1 parent f069282 commit d2ee950
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/core/List.pm
Expand Up @@ -326,22 +326,18 @@ my class List does Positional {
# specifier, but AFAIK nothing has been spec'd yet.
method uniq() {
my $seen := nqp::hash();
gather sink for @.list {
my str $which = nqp::unbox_s($_.WHICH);
unless nqp::existskey($seen, $which) {
take $_;
nqp::bindkey($seen, $which, 1);
}
}
my str $which;
grep {
$which = nqp::unbox_s($_.WHICH);
nqp::bindkey($seen, $which, 1) unless nqp::existskey($seen, $which);
}, @.list;
}

my @secret;
method squish() {
my $last = @secret;
gather sink for @.list {
take $_ if $_ !=== $last;
$last = $_;
}
my $grepped;
grep { $grepped = $_ !=== $last; $last = $_; $grepped }, @.list;
}

multi method gist(List:D:) { join ' ', map { $_.gist }, @(self) }
Expand Down

0 comments on commit d2ee950

Please sign in to comment.