Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^6: Fold a list using map splices

by Aristotle (Chancellor)
on Sep 04, 2004 at 03:01 UTC ( #388475=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    sub mapn (&@) {
        my ( $callback, $n ) = splice @_, 0, 2;
        map $callback->( splice @_, 0, $n ), 0 .. @_ / $n -1;
    }
    
  2. or download this
    sub mapnz (&@) {
        my ( $callback, $n ) = splice @_, 0, 2;
    ...
            $callback->( @_[ $i .. ( $j += $n ) - 1 ] );
        } 0 .. @_ / $n - 1;
    }
    
  3. or download this
    sub mapn (&@) {
        my ( $callback, $n ) = splice @_, 0, 2;
    ...
            $callback->( splice @_, 0, $n );
        } 0 .. @_ / $n - 1;
    }
    
  4. or download this
    sub mapn (&@) {
        my ( $callback, $n ) = splice @_, 0, 2;
    ...
            $callback->( @_[ $i .. ( $j += $n ) - 1 ] );
        } 0 .. @_ / $n - 1;
    }
    
  5. or download this
    sub mapnz (&@) {
        my ( $callback, $n ) = splice @_, 0, 2;
        push @_, ( undef ) x ( -@_ % $n );
        map $callback->( splice @_, 0, $n ), 0 .. @_ / $n - 1;
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://388475]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2021-04-15 17:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?