Subject: | feature request: slide |
Date: | Sun, 13 Jan 2019 16:50:13 +0100 |
To: | bug-Scalar-List-Utils [...] rt.cpan.org |
From: | "Ruud H.G. van Tol" <rvtol [...] isolution.nl> |
sub slide (&@) {
# like reduce, but returns intermediate values
my $f = shift;
my $v0= shift;
@_ or return $v0;
my $pkg= caller;
my $a= $v0;
no strict 'refs';
local *{"$pkg\::a"} = \$a;
my $glob_b= \*{"$pkg\::b"};
$v0, map {
my $b= $_;
local *$glob_b= \$b;
local $_;
$a= $f->();
} @_;
}
Example:
my $e= 1+ sum slide { $a / $b } 1..19; # 2.71828182845905
-- Ruud