-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectMonad.php
More file actions
29 lines (23 loc) · 787 Bytes
/
Copy pathObjectMonad.php
File metadata and controls
29 lines (23 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
namespace PhatCats\ObjectTypeclass;
trait ObjectMonad {
use ObjectApplicative;
/**
* @param callable $f A function of one argument whose type is the type of
* value contained in the monad. The return type of $f should be the same as
* this monad, i.e., if this monad is a Maybe, then the return type of $f
* should be a Maybe.
* @return The value returned by $f.
*/
abstract function flatMap(callable $f);
/**
* Removes one layer of structure.
* @return The type of the return value should be the same type as this ObjectMonad.
*/
function join() {
// the identity function. Can you believe PHP doesn't have one in the
// standard lib?
$id = function ($x) { return $x; };
return $this->flatMap($id);
}
}