- Write your own DLS (domain specific language)
- Decouple implementation from interpretation.
+#### Echo program
Example Free Monad example of `echo program` can be found here:
- [FreeMonadTest.php](/example/FreeMonadTest.php) - example based on first implementation of Free
- [Free2MonadTest.php](/example/Free2MonadTest.php) - example based on second implementation of Free, based on [Haskell implementation](https://hackage.haskell.org/package/free-4.12.4/docs/Control-Monad-Free-Class.html)
+#### DSL for `BDD` tests
+Example that use `Free Monad` to creates simple DSL (Domain Specific Language) to define BDD type of framework:
+
+- [Free2BddStyleDSLTest.php](/example/Free2BddStyleDSLTest.php) - example based on second implementation of Free, based on [Haskell implementation](https://hackage.haskell.org/package/free-4.12.4/docs/Control-Monad-Free-Class.html)
+
+```php
+$state = [
+ 'productsCount' => 0,
+ 'products' => [],
+];
+
+$scenario =
+ Given('Product in cart', $state)
+ ->When("I add product 'coca-cola'")
+ ->When("I add product 'milk'")
+ ->Then("The number of products is '2'");
+
+$result = $scenario->Run([
+ "/^I add product '(.*)'/" => function ($state, $productName) {
+ $state['productsCount'] += 1;
+ $state['products'][] = $productName;
+
+ return $state;
+ },
+], [
+ "/^The number of products is '(\d+)'/" => function ($state, int $expected) {
+ return $state['productsCount'] === $expected;
+ },
+]);
+```
### Haskell Do Notation in PHP
**NOTE:** This is experimental feature.