The uniq functions


examples/arrays/unique.p6
#!/usr/bin/perl6
use v6;

my @duplicates = 1, 1, 2, 5, 1, 4, 3, 2, 1;
say @duplicates.perl;
# prints [1, 1, 2, 5, 1, 4, 3, 2, 1]


my @unique = uniq @duplicates;
say @unique.perl;

# prints [1, 2, 5, 4, 3]


my @chars = <b c a d b a a a b>;
say @chars.perl;

# prints ["b", "c", "a", "d", "b", "a", "a", "a", "b"]

my @singles = uniq @chars;
say @singles.perl;    

# prints ["b", "c", "a", "d"]


Copyright 2006, 2007, 2008, 2009, 2010 Gabor Szabo http://szabgab.com/ Index | TOC
If you are interested in on-site trainings by the author, please contact me directly.

Online courses:

Would you like to get
updated when I publish
the next article?

Follow me:

Google Plus Twitter RSS feed