Skip to content

PerlFPM (Perl Functional Programming Module) contains functionalities to utilize functional programming paradigm for Perl 5.

License

Notifications You must be signed in to change notification settings

HaroldHS/PerlFPM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PerlFPM

PerlFPM (Perl Functional Programming Module) contains functionalities to utilize functional programming paradigm for Perl 5.

NOTE: This module is not intended for utilizing all concepts of functional programming but to utilize some aspects of functional programming paradigm. In addition, this module is not fully functional, so there are parts that use imperative approach in the underlying mechanism. As a result, there are 2 implementations for the same functionality (e.g. for mapping, imprMap = imperative map & mapping = functional map).


Installation / Run

No additional program is needed for running this module. Just append this code snippet inside the perl file:

use lib 'directory of PerlFPM and append /lib';
use PerlFPM qw();

NOTE: Obtaining the directory path of PerlFPM could be done by traversing inside the directory of PerlFPM and run pwd command for Linux or chdir command for Windows.


As an example: If PerlFPM folder located in /home/user/PerlFPM, then append this code snippet inside the perl file.

use lib '/home/user/PerlFPM/lib';
use PerlFPM qw(imprMap);

Example

NOTE: Sample files example*.pl inside /examples folder are provided in order to show the usage of PerlFPM.


Imperative implementation

use lib '/home/user/PerlFPM/lib';
use PerlFPM qw(addn imprMap);

my @input = (1,2,3);
my $addn1_function = addn->(1);
my @result = imprMap(\&$addn1_function, \@input);
print "$_ " for @result; # 2 3 4

Functional implementation

use lib '/home/user/PerlFPM/lib';
use PerlFPM qw(subtraction zippingWithFunction perlListToFunctionalList printFunctionalList);

# Input
my @input1 = (4,5,6);
my @input2 = (2,3);
my $subtract = subtraction;

# Convert to functional list
my $flist1 = perlListToFunctionalList(\@input1);
my $flist2 = perlListToFunctionalList(\@input2);

my $result = zippingWithFunction(\&$subtract, $flist1, $flist2);
printFunctionalList($result, ", "); # (2, 2)

Features

  • Type
  • Currying
  • High Order Function
  • Function Signature
  • Application

About

PerlFPM (Perl Functional Programming Module) contains functionalities to utilize functional programming paradigm for Perl 5.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages