in reply to Re^3: reduce like iterators
in thread reduce like iterators

> > my @b = @{ reduce { push @$a, $b if @$a && $b ne $a->[-1]; $a } [], @a };

And I said:

> (Sure I could use $a as an array-ref for accumulation, not very elegant...)

Cheers Rolf

Replies are listed 'Best First'.
Re^5: reduce like iterators
by ikegami (Patriarch) on Jan 03, 2011 at 19:18 UTC
    But as I've shown in the update, it's not very elegant if you don't either.

      It's a bit cleaner if ($state, @to_push) is returned.

      my @b = list_reduce { undef, !@$_ || $b ne $_->[-1] ? $b : () } undef, + @a; my @b = list_reduce { 0, !@$_ || $b ne $_->[-1] ? $b : () } 1, @a; my @b = list_reduce { $b, defined($b) && $b ne $a ? $b : () } undef, @ +a; my @b = list_reduce { $b, grep defined && $_ ne $a, $b } undef, @a;

      (@a may not start with undef for the last two to work properly.)

      This actually looks like map now (as it should).