In Any§
See primary documentation in context for method repeated
multi method repeated() multi method repeated( :&as!, :&with! ) multi method repeated( :&as! ) multi method repeated( :&with! )
Similarly to unique
, finds repeated elements in values
(as a routine) or in the object, using the :as
associative argument as a normalizing function and :with
as equality function.
<1 -1 2 -2 3>.repeated(:as(&abs),:with(&[==])).say; # OUTPUT: «(-1 -2)» (3+3i, 3+2i, 2+1i).repeated(as => *.re).say; # OUTPUT: «(3+2i)»
It returns the last repeated element before normalization, as shown in the example above. See repeated
for more examples that use its sub form.
In Supply§
See primary documentation in context for method repeated
method repeated(Supply:D: :&as, :&with)
Creates a supply that only provides repeated values, as defined by the optional :as
and :with
parameters (same as with unique
).
my $supply = Supply.from-list(<a A B b c b C>).repeated(:as(&lc)); $supply.tap(&say); # OUTPUT: «AbbC»
See repeated
for more examples that use its sub form.
Note: Available since version 6.e (Rakudo 2020.01 and later).
In Independent routines§
See primary documentation in context for routine repeated
multi repeated(+values, |c)
This returns a sequence of repeated values from the invocant/argument list. It takes the same parameters as unique, but instead of passing through any elements when they're first seen, they're only passed through as soon as they're seen for the second time (or more).
Examples:
say <a a b b b c c>.repeated; # OUTPUT: «(a b b c)» say <a b b c c b a>.repeated; # OUTPUT: «(b c b a)» say <a A B b c b C>.repeated(:as(&lc)); # OUTPUT: «(A b b C)» my @list = %(a => 42), %(b => 13), %(a => 42); say @list.repeated(:with(&[eqv])) # OUTPUT: «({a => 42})»
As in the case of unique
the associative argument :as
takes a Callable that normalizes the element before comparison, and :with
takes a the equality comparison function that is going to be used.