Remove experimental Monad\Control\doo
authorwidmogrod <widmogrod@gmail.com>
Thu, 21 Dec 2017 21:17:25 +0000 (22:17 +0100)
committerwidmogrod <widmogrod@gmail.com>
Thu, 21 Dec 2017 21:17:25 +0000 (22:17 +0100)
README.md
composer.json
src/Monad/Control/functions.php [deleted file]

index 85544d4..6debd4a 100644 (file)
--- a/README.md
+++ b/README.md
@@ -276,43 +276,6 @@ $result = $scenario->Run([
 ]);
 ```
 
-### Haskell Do Notation in PHP
-**NOTE:** This is experimental feature.
-
-``` php
-use Widmogrod\Monad\IO as IO;
-use Widmogrod\Monad\Control as C;
-use Widmogrod\Functional as f;
-
-$do = control\doo([
-    IO\putStrLn('Your name:'),                      // put on screen line: Your name:
-    '$name' =>
-        IO\getLine(),                               // prompt for the name, and store it in '$name' key
-
-    control\runWith(IO\putStrLn, ['$name']),        // put on screen entered name
-
-    IO\putStrLn('Your surname:'),                   // put on screen line: Your surname:
-    '$surname' =>
-        IO\getLine(),                               // prompt for surname, and store it in '$surname' key
-
-    control\runWith(function($surname, $name) {     // put on screen: "Hello $surname, $name"
-        return IO\putStrLn(sprintf("Hello %s, %s", $surname, $name));
-    }, ['$surname', '$name']),
-]);
-
-// performs operation, before that nothings happens from above code.
-$do->run();
-```
-
-Example output:
-```txt
-Your name:
-Gabriel
-Your surname:
-Habryn
-Hello Habryn, Gabriel
-```
-
 ### Sequencing Monad operations
 This variant of `sequence_` ignores the result.
 
index 9c6ab55..05d9f19 100644 (file)
@@ -39,7 +39,6 @@
       "src/Functional/strings.php",
       "src/Functional/monoid.php",
       "src/Functional/setoid.php",
-      "src/Monad/Control/functions.php",
       "src/Monad/Either/functions.php",
       "src/Monad/Maybe/functions.php",
       "src/Monad/Free/functions.php",
diff --git a/src/Monad/Control/functions.php b/src/Monad/Control/functions.php
deleted file mode 100644 (file)
index 300b3c6..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-<?php
-
-namespace Widmogrod\Monad\Control;
-
-use Widmogrod\Monad as M;
-
-/**
- * doo :: State IO m => [m a] -> m a
- *
- * Haskell like "do notation" simple implementation.
- * Since "do" is reserved keyword in PHP then I use "doo".
- *
- * @param array|M\IO[] $monads
- *
- * @return M\IO
- */
-function doo(array $monads)
-{
-    return M\IO::of(function () use ($monads) {
-        $result = null;
-        $data = [];
-        // TODO do it by foldWithKeys
-        foreach ($monads as $key => $monad) {
-            // TODO do it better - maybe?
-            if ($monad instanceof M\IO) {
-                $monad = ioState($monad);
-            }
-
-            $state = [$key, $data];
-            [$result, [$_, $data]] = M\State\runState($monad, $state);
-        }
-
-        return $result;
-    });
-}
-
-/**
- * runWith :: (a -> IO b) -> [a] -> State IO b
- *
- * @param callable $function
- * @param array $argsNames
- *
- * @return M\State
- */
-function runWith(callable $function, array $argsNames)
-{
-    return M\State::of(function (array $state) use ($function, $argsNames) {
-        [$key, $data] = $state;
-
-        $args = array_reduce($argsNames, function ($base, $index) use ($data) {
-            $base[$index] = $data[$index];
-
-            return $base;
-        }, []);
-
-        $value = $function(...$args)->run();
-
-        $data[$key] = $value;
-        $newState = [$key, $data];
-
-        return [$value, $newState];
-    });
-}
-
-/**
- * ioState :: IO a -> State IO a
- *
- * @param M\IO $io
- *
- * @return M\State
- */
-function ioState(M\IO $io)
-{
-    return M\State::of(function ($state) use ($io) {
-        [$key, $data] = $state;
-
-        $value = $io->run();
-
-        $data[$key] = $value;
-        $newState = [$key, $data];
-
-        return [$value, $newState];
-    });
-}