sub moving (&func, *@data) { # Note: "arity" means how many params the sub takes my @results; for 0..@data-&block.arity -> $from { my $to = $from + &block.arity - 1; push @results, func(@data[$from..$to]); } return @results; } @average_3 = moving { ($^x+$^y+$^z)/3 } @values; @average_4 = moving { ($^w+$^x+$^y+$^z)/4 } @values; @local_max_3 = moving { max $^x, $^y, $^z } @values; # etc.