Introduce contra example - how control flow looks like without do notation
authorwidmogrod <widmogrod@gmail.com>
Mon, 1 Jan 2018 22:15:08 +0000 (23:15 +0100)
committerwidmogrod <widmogrod@gmail.com>
Mon, 1 Jan 2018 22:25:22 +0000 (23:25 +0100)
Introduce contr example - how control flow looks like without do notation

example/FreeDooDSLTest.php

index a77ee47..c5f5680 100644 (file)
@@ -4,14 +4,14 @@ declare(strict_types=1);
 
 namespace example;
 
+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;
-use Widmogrod\Monad\Identity;
 
 class FreeDooDSLTest extends \PHPUnit\Framework\TestCase
 {
-    public function test_it()
+    public function test_example_with_do_notation()
     {
         $result = doo(
             let('a', Identity::of(1)),
@@ -26,4 +26,21 @@ class FreeDooDSLTest extends \PHPUnit\Framework\TestCase
 
         $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);
+    }
 }