routine repeated

Documentation for routine repeated assembled from the following types:

class Any

From Any

(Any) method repeated

Defined as:

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.

language documentation Independent routines

From Independent routines

(Independent routines) routine repeated

Defined as:

multi sub    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).


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 = %(=> 42), %(=> 13), %(=> 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.