Skip Menu |

This queue is for tickets about the List-MoreUtils CPAN distribution.

Report information
The Basics
Id: 85797
Status: open
Priority: 0/
Queue: List-MoreUtils

People
Owner: Nobody in particular
Requestors: smls75 [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



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
I would quite like something that works like List::Util's "pairs", but working for n rather than 2. Here's how pairs works: @pairs = pairs "a", "b", "c", "d", "e", "f"; # @pairs is (["a", "b"], ["c", "d"], ["e", "f"]) I would quite like something like: @groups = ngroups 3, "a", "b", "c", "d", "e", "f"; # @groups is (["a", "b", "c"], ["d", "e", "f"])
What's wrong with natatime?