Skip to content

Commit f65e122

Browse files
committed
Document :with on List.unique
1 parent 39db29a commit f65e122

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

doc/Type/List.pod

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -556,19 +556,20 @@ Examples:
556556
557557
Defined as:
558558
559-
multi sub unique(*@values, :&as) returns Seq:D
560-
multi method unique(List:D:, :&as) returns Seq:D
559+
multi sub unique(*@values, :&as, :&with) returns Seq:D
560+
multi method unique(List:D:, :&as, :&with) returns Seq:D
561561
562562
Usage:
563563
564-
unique LIST, :COMPARE_AS
565-
LIST.unique(:COMPARE_AS)
564+
unique LIST, :COMPARE_AS, :COMPARE_WITH
565+
LIST.unique(:COMPARE_AS, :COMPARE_WITH)
566566
567567
Returns a sequence of unique values from the invocant/argument list, such
568568
that only the first occurrence of each duplicated value remains in the
569-
result list. C<unique> uses the semantics of the L<===> operator to decide whether
570-
two objects are the same. The order of the original list is preserved even as
571-
duplicates are removed.
569+
result list. C<unique> uses the semantics of the L<===> operator to decide
570+
whether two objects are the same, unless the optional C<:with> parameter is
571+
specified with another comparator. The order of the original list is preserved
572+
even as duplicates are removed.
572573
573574
Examples:
574575
@@ -579,13 +580,22 @@ Examples:
579580
objects are adjacent.)
580581
581582
The optional C<:as> parameter allows you to normalize/canonicalize the elements
582-
before unique-ing. The values are transformed for the purposes of comparison, but
583-
it's still the original values that make it to the result list:
583+
before unique-ing. The values are transformed for the purposes of comparison,
584+
but it's still the original values that make it to the result list:
584585
585586
Example:
586587
587588
say <a A B b c b C>.unique(:as(&lc)) # a B c
588589
590+
One can also specify the comparator with the optional C<:with> parameter. For
591+
instance if one wants a list of unique hashes, one could use the C<eqv>
592+
comparator.
593+
594+
Example:
595+
596+
my @list = {a => 42}, {b => 13}, {a => 42};
597+
say @list.unique(:with(&[eqv])) # {a=>42} {b=>13}
598+
589599
=head2 routine squish
590600
591601
Defined as:

0 commit comments

Comments
 (0)