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

But as I've shown in the update, it's not very elegant if you don't either.

Replies are listed 'Best First'.
Re^6: reduce like iterators
by ikegami (Patriarch) on Jan 03, 2011 at 19:28 UTC

    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).