in reply to Prototype like sort()?

I'm not sure what you are after. Do you mean something like this?

use strict; use warnings; use 5.022; use List::Util qw{ sum }; sub groupsOf (&$@); say for groupsOf { sum @_ } 3, 1 .. 20; sub groupsOf (&$@) { my $rcToRun = shift; my $groupsOf = shift; my $rcDoIt; $rcDoIt = sub { $rcToRun->( map shift, 1 .. ( @_ < $groupsOf ? @_ : $groupsOf ) ), @_ ? &$rcDoIt : (); }; &$rcDoIt; }

The output.

6 15 24 33 42 51 39

If this guess is wrong please clarify your requirement.

Cheers,

JohnGG