☺唐鳳☻
and 1 contributors

NAME

fp - Functional programming for Perl 6

SYNOPSIS

  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";

DESCRIPTION

This is an experimental module which eases the use of functional programming techniques in Perl 6.

OPERATORS

infix:<∘> (Code &f, Code &g)

Function composition, think of Haskell's .. There's also the ASCII equivalent o.

infix:<`map`> (Code &f, *@y)

infix:<`grep`> (Code &f, *@y)

Infix versions of map and 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.

FUNCTIONS

identity($x)

The identity function.

const($x)

Returns a new function which always returns $x.

tail(@array)

Returns all except the first element of @array.

init(@array)

Returns all except the last element of @array.

replicate(Int $n, Code &f)

Runs &f $n times and returns the results.

BUGS

This module is currently somewhat short, additions welcome! :)

AUTHOR

Ingo Blechschmidt <iblech@web.de>

1 POD Error

The following errors were encountered while parsing the POD:

Around line 45:

Non-ASCII character seen before =encoding in '∘'. Assuming UTF-8