fp - Functional programming for Perl 6
use fp; (&say o &int)(10/3); # 3 (&say ∘ &int)(10/3); # 3 { $_ % 2 == 0 } `grep` [1,2,3,4]; # [2,4] { $_ * 2 } `map` [1,2,3]; # [2,4,6] my $pair = key ⇒ "value";
This is an experimental module which eases the use of functional programming techniques in Perl 6.
infix:<∘> (Code &f, Code &g)
Function composition, think of Haskell's .. There's also the ASCII equivalent o.
.
o
infix:<`map`> (Code &f, *@y)
infix:<`grep`> (Code &f, *@y)
Infix versions of map and grep.
map
grep
These will go when we can define own metaoperators (like [...] or »...«). Then, all functions can be "infixized".
[...]
»...«
infix:<⇒> ($key, $value)
Pair constructor (equivalent to =>).
=>
≥
≤
≠
Standard comparision operators.
≣
≡
Equivalent to =:=.
=:=
prefix:<∑>(@nums)
prefix:<∏>(@nums)
Sum and product.
postfix:<!>(Int $x)
Factorial.
id($x)
The identity function.
const($x)
Returns a new function which always returns $x.
$x
tail(@array)
Returns all except the first element of @array.
@array
init(@array)
Returns all except the last element of @array.
replicate(Int $n, Code &f)
Runs &f $n times and returns the results.
&f
$n
This module is currently somewhat short, additions welcome! :)
Ingo Blechschmidt <iblech@web.de>
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in '∘'. Assuming UTF-8
To install Perl6::Pugs, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perl6::Pugs
CPAN shell
perl -MCPAN -e shell install Perl6::Pugs
For more information on module installation, please visit the detailed CPAN module installation guide.