I'm finding myself in need of a function to do operation on pairs of
elements in a list like so:
0 and 1
1 and 2
2 and 3
3 and 4
and so on
For example...
# 0 and 1, 1 and 2, 2 and 3.
print join ", ", slide { "$a and $b" } (0, 1, 2, 3);
This would be useful for performing operations *between* two elements in
a list. It replaces loops like this:
my $last_thing;
for my $thing (@things) {
return $last_thing if $thing > $blah;
$last_thing = $thing;
}
With this:
my $thing;
slide { $thing = $a if $b > $blah } @things;
It would be nice to avoid having a whole set of these functions (grep,
map, first, etc...) by perhaps having an iterator which can generate
pairs without having to create a double side list.
my $slider = make_slider \@things;
while( my($a, $b) = $slider->next ) {
...
}
This may be out of scope for List::MoreUtils.