Skip to content

Commit 02ee80d

Browse files
author
Carl Masak
committed
[S32/Containers] explain uniq/squish a bit more
- both uniq and squish preserve order - omit some implementation details which shouldn't be in the spec - give examples
1 parent c7a5da2 commit 02ee80d

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

S32-setting-library/Containers.pod

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,14 @@ C<is canonicalized(&lc)>.)
455455

456456
Returns a list of unique values from the invocant/argument
457457
list. C<uniq> uses C<< &infix:<===> >> semantics to compare whether
458-
two objects are the same. The function does not use C<===> directly,
459-
however; it is actually implemented via an object-keyed hash (such as
460-
an object set), so that any instance of a given identity suppresses all
461-
subsequent instances of that identity, even if they are not contiguous
462-
in the list. (Use C<squish> instead if you know the input is sorted
463-
such that identical objects are adjacent.)
458+
two objects are the same. The order of the original list is preserved
459+
even as duplicates are removed.
460+
461+
say <a a b b b c c>.uniq # a b c
462+
say <a b b c c b a>.uniq # a b c
463+
464+
(Use C<squish> instead if you know the input is sorted such that identical
465+
objects are adjacent.)
464466

465467
=item squish
466468

@@ -471,9 +473,13 @@ such that identical objects are adjacent.)
471473
Returns a list of values from the invocant/argument list where runs
472474
of more than one object of the same identity are squished down to
473475
a single instance. Like C<uniq>, C<squish> uses C<< &infix:<===> >>
474-
semantics to compare whether two objects are the same. Unlike,
475-
C<uniq>, this function does not need to keep a hash of all previous
476-
identities; it simply tracks the previous one, and uses C<===> directly.
476+
semantics to compare whether two objects are the same. Unlike
477+
C<uniq>, this function only removes adjacent duplicates; identical
478+
objects further apart are still kept. The order of the original list
479+
is preserved even as duplicates are removed.
480+
481+
say <a a b b b c c>.squish # a b c
482+
say <a b b c c b a>.squish # a b c b a
477483

478484
=item min
479485

0 commit comments

Comments
 (0)