Ruby style functional programming in Perl!

So recently I was asking if andand exists in perl (here and here) and someone implemented it! How awesome is that? See it here.

Anyway, so I looked at the code and figured, “Well heck, if it’s that easy, I should do this for map and join on arrays!”

It was already done! The autobox::Core module does it already! You have to use more javascript-y syntax instead of regular perl-ish, but I think it makes things more clear anyway.

Example:

#!/usr/bin/perl
use feature ":5.10";
use autobox::Core;
my @foo = (1,2,3);

say join( ',', map { $_ * 2 } @foo );
say @foo->map(sub { $_ * 2 })->join(',');

To be perfectly clear, you would probably think of the first one as: we are joining the results of the map that multiplies each item by two and the second one as: multiply each item by two and then join them with a comma.

Anyway, I am so stoked to use this at work.

Posted Fri, Jan 9, 2009

If you're interested in being notified when new posts are published, you can subscribe here; you'll get an email once a week at the most.