6

FAQ: In Raku, how to remove duplicates from a list to only get unique values?

my $arr = [1, 2, 3, 2, 3, 1, 1, 0];
# desired output [1, 2, 3, 0]
Tinmarino
  • 3,693
  • 24
  • 33

1 Answers1

8
  1. Use The built-in unique
@arr.unique  # (1 2 3 0)
  1. Use a Hash (alias map, dictionary)
my %unique = map {$_ => 1}, @arr;
%unique.keys;  # (0 1 2 3) do not rely on order
  1. Use a Set: same method as before but in one line and optimized by the dev team
set(@arr).keys
Tinmarino
  • 3,693
  • 24
  • 33