-
-
Save rsimoes/1522531 to your computer and use it in GitHub Desktop.
Functional definition of map in Perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
sub myMap(&@) { | |
!wantarray && @_ - 1 || @_ > 1 && ( | |
do { | |
local $_ = $_[1]; | |
$_[0]->(); | |
}, &myMap( $_[0], @_[2..$#_] ) | |
); | |
} | |
print myMap { "$_\n" } 1..4; | |
print scalar( myMap { "$_\n" } 1..4 ), "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment