Subject: | wish: make natatime behave more like map (and introduce twoatatime) |
Date: | Sun, 2 Jun 2013 08:19:03 +0200 |
To: | bug-List-MoreUtils [...] rt.cpan.org |
From: | "Sam S." <smls75 [...] gmail.com> |
The 'natatime' function breaks consistency and sacrifices convenience,
by returning an iterator - while most of the other functions in this
module take a code block as its their first argument and operate like
'map'.
Wouldn't it be possible to make 'natatime' work like 'map' as well?
For example like so:
natatime { say "$_->[0] and $_->[1]" } 2, @list
The second parameter is the number of items to take at a time, and
inside the code block $_ is a reference to an array that holds the n
items of this iteration.
This functionality could be added to the 'natatime' function without
breaking backwards compatibility, by making it check whether the first
parameter is a coderef of a number, and choose the corresponding
behavior based on that.
--
For the case of n=2, convenience (and performance) could be improved
even further by introducing a 'twoatatime' function, that uses $a and
$b instead of $_:
twoatatime { say "$a and $b" } @list