forked from widmogrod/php-functional
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFreeDooDSLTest.php
More file actions
46 lines (39 loc) · 1.27 KB
/
FreeDooDSLTest.php
File metadata and controls
46 lines (39 loc) · 1.27 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
declare(strict_types=1);
namespace example;
use PHPUnit\Framework\TestCase;
use Widmogrod\Monad\Identity;
use function Widmogrod\Monad\Control\Doo\doo;
use function Widmogrod\Monad\Control\Doo\in;
use function Widmogrod\Monad\Control\Doo\let;
class FreeDooDSLTest extends TestCase
{
public function test_example_with_do_notation()
{
$result = doo(
let('a', Identity::of(1)),
let('b', Identity::of(3)),
let('c', in(['a', 'b'], function (int $a, int $b): Identity {
return Identity::of($a + $b);
})),
in(['c'], function (int $c): Identity {
return Identity::of($c * $c);
})
);
$this->assertEquals(Identity::of(16), $result);
}
public function test_example_without_do_notation()
{
$result = Identity::of(1)
->bind(function ($a) {
return Identity::of(3)
->bind(function ($b) use ($a) {
return Identity::of($a + $b)
->bind(function ($c) {
return Identity::of($c * $c);
});
});
});
$this->assertEquals(Identity::of(16), $result);
}
}