Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Don't use 'uniq', use 'unique' instead
To prevent confusion by Unix 'uniq' users
  • Loading branch information
lizmat committed Oct 26, 2014
1 parent 3be145c commit 221ef4b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion S04-control.pod
Expand Up @@ -841,7 +841,7 @@ context. However, a C<take> function that is not in sink context
gathers its return objects I<en passant> and also returns them unchanged.
This makes it easy to keep track of what you last "took":

my @uniq = gather for @list {
my @squished = gather for @list {
state $previous = take $_;
next if $_ === $previous;
$previous = take $_;
Expand Down
10 changes: 5 additions & 5 deletions S17-concurrency.pod
Expand Up @@ -13,8 +13,8 @@ Synopsis 17: Concurrency

Created: 3 Nov 2013

Last Modified: 13 October 2014
Version: 22
Last Modified: 26 October 2014
Version: 23

This synopsis is based around the concurrency primitives and tools currently
being implemented in Rakudo on MoarVM and the JVM. It covers both things
Expand Down Expand Up @@ -652,12 +652,12 @@ Produces a C<Supply> that provides its original's Supply values multiplied by 5.

Produces a C<Supply> that provides its original's Supply values twice.

=item uniq
=item unique

my $u = $s.uniq( :as( {$_} ), :with( &[===] ), :expires(1) );
my $u = $s.unique( :as( {$_} ), :with( &[===] ), :expires(1) );

Produces a C<Supply> that only provides unique values, as defined by the
optional C<as> and C<with> named parameters (same as L<List.uniq>). The
optional C<as> and C<with> named parameters (same as L<List.unique>). The
optional C<expires> parameter specifies how long to wait (in seconds) before
"resetting" and not considering a value to have been seen, even if it's the
same as an old value.
Expand Down
24 changes: 12 additions & 12 deletions S32-setting-library/Containers.pod
Expand Up @@ -18,8 +18,8 @@ DRAFT: Synopsis 32: Setting Library - Containers.pod

Created: 19 Feb 2009 extracted from S29-functions.pod

Last Modified: 24 Feb 2014
Version: 47
Last Modified: 26 Oct 2014
Version: 48

If you read the HTML version, it is generated from the Pod in the specs
repository under
Expand Down Expand Up @@ -487,20 +487,20 @@ See L<http://www.nntp.perl.org/group/perl.perl6.language/16578>
for more details and examples (with C<is insensitive> meaning
C<is canonicalized(&lc)>.)

=item uniq
=item unique

multi method uniq(List:D: --> List:D, :&as)
multi method unique(List:D: --> List:D, :&as)

multi sub uniq(*@values --> List:D, :&as)

Returns a list of unique values from the invocant/argument list, such
that only the first occurrence of each duplicated value remains in the
result list. C<uniq> uses C<< &infix:<===> >> semantics to compare whether
result list. C<unique> uses C<< &infix:<===> >> semantics to compare whether
two objects are the same. The order of the original list is preserved even as
duplicates are removed.

say <a a b b b c c>.uniq # a b c
say <a b b c c b a>.uniq # a b c
say <a a b b b c c>.unique # a b c
say <a b b c c b a>.unique # a b c

(Use C<squish> instead if you know the input is sorted such that identical
objects are adjacent.)
Expand All @@ -509,13 +509,13 @@ The optional C<:as> parameter allows you to normalize/canonicalize the elements
before uniq-ing. The values are transformed for the purposes of comparison, but
it's still the original values that make it to the result list:

say <a A B b c b C>.uniq(:as(&lc)) # a B c
say <a A B b c b C>.unique(:as(&lc)) # a B c

This makes it possible to effectively compare with other comparison operators,
too. For example, if you want to compare with C< infix:<==> > semantics, this
might work for you:

say +uniq [100, 100e0, 200/2], :as(*.Num) # 1
say +unique [100, 100e0, 200/2], :as(*.Num) # 1

=item squish

Expand All @@ -525,16 +525,16 @@ might work for you:

Returns a list of values from the invocant/argument list where runs
of more than one value are replaced with only the first instance.
Like C<uniq>, C<squish> uses C<< &infix:<===> >> semantics to compare
whether two objects are the same. Unlike C<uniq>, this function only
Like C<unique>, C<squish> uses C<< &infix:<===> >> semantics to compare
whether two objects are the same. Unlike C<unique>, this function only
removes adjacent duplicates; identical values further apart are still
kept. The order of the original list is preserved even as duplicates
are removed.

say <a a b b b c c>.squish # a b c
say <a b b c c b a>.squish # a b c b a

The optional C< :as > parameter, just like with C< uniq >, allows values to be
The optional C< :as > parameter, just like with C< unique >, allows values to be
temporarily transformed before comparison.

=item min
Expand Down

0 comments on commit 221ef4b

Please sign in to comment.