in reply to Re: 99 Problems in Perl6
in thread 99 Problems in Perl6

Couldn't that be done easier with take/gather?

my @in = <a a a a b c c a a d e e e e>; my @out = gather { for @in -> $i { state $last; take $i if $i ne $last; $last = $i; }}; say @out;

___________
Eric Hodges

Replies are listed 'Best First'.
Re^3: 99 Problems in Perl6
by gaal (Parson) on Feb 21, 2007 at 20:45 UTC
    TIMTOWTDI of course, but syntax updates to gather since the OP allow you to write it as:

    my @in = <a a a a b c c a a d e e e e>; say gather for @in -> $i { state $last; $last = take $i if $i ne $last; };

      Excellent. I'd been looking for a better syntax as i was sure there was one..now if perl6 just had a way to access the last element returned by for you could simplify it even one more time.


      ___________
      Eric Hodges