Skip to content

Commit 97ecdd3

Browse files
committed
Introduce contra example - how control flow looks like without do notation
Introduce contr example - how control flow looks like without do notation
1 parent c3e000d commit 97ecdd3

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

example/FreeDooDSLTest.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
namespace example;
66

7+
use Widmogrod\Monad\Identity;
78
use function Widmogrod\Monad\Control\Doo\doo;
89
use function Widmogrod\Monad\Control\Doo\in;
910
use function Widmogrod\Monad\Control\Doo\let;
10-
use Widmogrod\Monad\Identity;
1111

1212
class FreeDooDSLTest extends \PHPUnit\Framework\TestCase
1313
{
14-
public function test_it()
14+
public function test_example_with_do_notation()
1515
{
1616
$result = doo(
1717
let('a', Identity::of(1)),
@@ -26,4 +26,21 @@ public function test_it()
2626

2727
$this->assertEquals(Identity::of(16), $result);
2828
}
29+
30+
public function test_example_without_do_notation()
31+
{
32+
$result = Identity::of(1)
33+
->bind(function ($a) {
34+
return Identity::of(3)
35+
->bind(function ($b) use ($a) {
36+
return Identity::of($a + $b)
37+
->bind(function ($c) {
38+
return Identity::of($c * $c);
39+
});
40+
});
41+
42+
});
43+
44+
$this->assertEquals(Identity::of(16), $result);
45+
}
2946
}

0 commit comments

Comments
 (0)