Applicative functors

Let's take an instance of our identity functor, holding some integer and a curryied version of an add function:

$add = curry(function(int $a, int $b) { return $a + $b; }); 
$id = new IdentityFunctor(5); 

Now, what happens when we try to map the $add parameter on our functor? Consider the following code:

$hum = $id->map($add); 
echo get_class($hum->get()); 
// Closure 

As you may have guessed, our functor now contains a closure representing a partially applied add parameter with the value 5 as the first parameter. You can use the get method to retrieve the function and use it, but it is not really that useful.

Another possibility would be to map another function, taking our function as a parameter, and doing something with ...

Get Functional PHP now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.