Skip to content

Commit

Permalink
Add simple-minded version of uniq.
Browse files Browse the repository at this point in the history
  • Loading branch information
colomon committed Feb 15, 2010
1 parent ee93de4 commit 2eb5f98
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/core/Any-list.pm
Expand Up @@ -150,6 +150,20 @@ augment class Any {
}
return @args[0];
}

# This needs a way of taking a user-defined comparison
# specifier, but AFAIK nothing has been spec'd yet.
# CHEAT: Almost certainly should be hashed on something
# other than the stringification of the objects.
multi method uniq() {
my %seen;
gather for @.list {
unless %seen{$_} {
take $_;
%seen{$_} = 1;
}
}
}
}

our proto sub join (Str $separator = '', *@values) { @values.join($separator); }
Expand All @@ -160,5 +174,6 @@ our proto sub grep($test, @values) { @values.grep($test); }
our proto sub first($test, @values) { @values.first($test); }
our proto sub min($by, *@values) { @values.min($by); }
our proto sub max($by, *@values) { @values.max($by); }
our proto sub uniq(@values) { @values.uniq; }

# vim: ft=perl6

0 comments on commit 2eb5f98

Please sign in to comment.