NAME
FP::Ops -- function wrappers around Perl ops
SYNOPSIS
use FP::List; use FP::Stream; use FP::Lazy; use FP::Equal 'is_equal';
use FP::Ops qw(add subt applying);
# Lazy fibonacci sequence using \&add
our $fibs; $fibs =
cons 1, cons 1, lazy { stream_zip_with \&add, Keep($fibs), rest $fibs };
is_equal $fibs->take(10),
list(1, 1, 2, 3, 5, 8, 13, 21, 34, 55);
# For each list entry, call `subt` (subtract) with the values in the
# given array or sequence.
is_equal list([4], [4,2], list(4,2,-1))->map(applying \&subt),
list(-4, 2, 3);
DESCRIPTION
There's no way to take a code reference to Perl operators, hence a subroutine wrapper is necessary to use them as first-class values (like pass them as arguments to higher-order functions like list_map / ->map). This module provides them.
Also similarly, `the_method("foo", @args)` returns a function that does a "foo" method call on its argument, passing @args and then whatever additional arguments the function receives.
`cut_method` is a variant of the_method which takes the object as the first argument: `cut_method($obj,"foo",@args)` returns a function that does a "foo" method call on $obj, passing @args and then whatever additional arguments the function receives.
Also, `binary_operator("foo")` returns a function that uses "foo" as operator between 2 arguments. `unary_operator("foo")` returns a function that uses "foo" as operator before its single argument. CAREFUL: make sure the strings given as the first argument to these are secured, as they are passed to eval and there is no safety check!
NOTE
This is alpha software! Read the status section in the package README or on the website.