P08 - Eliminate consecutive duplicates of list elements.

Author: Eric Hodges

Specification

P08 (**) Eliminate consecutive duplicates of list elements.
    If a list contains repeated elements they should be replaced with a
    single copy of the element. The order of the elements should not be
    changed.

Example

> say ~compress()
a b c a d e

Source code: P08-eric256.pl

use v6;

die "Example doesn't yet work in Niecza" if $*VM ~~ 'niecza';

sub compress (@in) {
    my @return;
    my $last;
    for @in -> $i {
        FIRST { $last = '' }
        if ($i ne $last) {
            @return.push($i);
            $last = $i;
        }
    }
    return @return;
}

compress().perl.say;