Front page | perl.perl6.language |
Postings from May 2005
Re: [S29] uniq
Thread Previous
|
Thread Next
From:
Ingo Blechschmidt
Date:
May 19, 2005 11:33
Subject:
Re: [S29] uniq
Message ID:
d6ilss$922$1@sea.gmane.org
Hi,
Mark Overmeer wrote:
> * Ingo Blechschmidt (iblech@web.de) [050519 16:52]:
>> Should it be possible to give an own comparator block, similar as
>> with grep? E.g.
>> uniq <a b a a c d>; # <a b a c d>
>>
>> uniq:{ abs $^a == abs $^b } 42, 23, -23, 23, 42
>> # 42, 23, 42
>
> 'uniq' differs from 'sort' because there is no order relationship
> between
> the elements.
quoting Damian's original mail[1]:
> uniq - remove duplicates without reordering
^^^^^^^^^^^^^^^^^^
> A quick algorithm for finding the unique elements in
> perl5 is
[...]
Yeah, or the Perl 6:
sub uniq(*@elems) {
my %h;
%h{@elems}ยป.++;
return keys %h;
}
# Or
sub uniq(*@elems) {
my %h;
%h{@elems} = (undef) xx Inf;
return keys %h;
}
# thousand other ways ommitted :)
--Ingo
[1] http://groups.google.com/groups?selm=420DB295.3000902%40conway.org
--
Linux, the choice of a GNU | "The future is here. It's just not widely
generation on a dual AMD | distributed yet." -- William Gibson
Athlon! |
Thread Previous
|
Thread Next