P08 - 消除列表元素中的连续重复项。
作者:Ryan Connelly
示例
> say eliminate-consecutive-duplicates(<a a a a a b b c b d e e>); a b c b d e
源代码: P08-topo.pl
use v6;
sub eliminate-consecutive-duplicates(@list)
{
my $last = ();
gather for @list -> $e
{
# ~~ is the smart match operator.
# It's the closest thing I can think of to a comparison function
# which doesn't enforce a particular context... should be alright. :-)
next if $e ~~ $last;
$last = $e;
take $e;
}
}
say "{eliminate-consecutive-duplicates(<a a a a a b b c b d e e>)}";
Perl 6 示例