From eae430ece63efb4e387cc9f324a68c54e2858467 Mon Sep 17 00:00:00 2001 From: Mathieu Ledru Date: Sat, 13 Nov 2021 20:04:59 +0100 Subject: [PATCH 1/2] :sparkles: Add Lambda Rail --- packages/php/composer.json | 3 +- packages/php/src/Driver/ReactDriver.php | 4 +- packages/php/src/Rail/LambdaRail.php | 18 ++++++++ packages/php/tests/Rail/LambdaRailTest.php | 54 ++++++++++++++++++++++ 4 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 packages/php/src/Rail/LambdaRail.php create mode 100644 packages/php/tests/Rail/LambdaRailTest.php diff --git a/packages/php/composer.json b/packages/php/composer.json index a6ccfe6c..badf1d93 100644 --- a/packages/php/composer.json +++ b/packages/php/composer.json @@ -17,7 +17,8 @@ "monad" ], "require": { - "php": "^8.0" + "php": "^8.0", + "loophp/combinator": "^2.0" }, "require-dev": { "amphp/amp": "^2.6", diff --git a/packages/php/src/Driver/ReactDriver.php b/packages/php/src/Driver/ReactDriver.php index 3daf9f94..ade67de7 100644 --- a/packages/php/src/Driver/ReactDriver.php +++ b/packages/php/src/Driver/ReactDriver.php @@ -5,7 +5,7 @@ namespace RFBP\Driver; use Closure; -use React\EventLoop\Factory; +use React\EventLoop\Loop; use React\EventLoop\LoopInterface; use React\EventLoop\TimerInterface; use RFBP\DriverInterface; @@ -28,7 +28,7 @@ public function __construct(?LoopInterface $eventLoop = null) } if (null === $eventLoop) { - $this->eventLoop = Factory::create(); + $this->eventLoop = Loop::get(); } else { $this->eventLoop = $eventLoop; } diff --git a/packages/php/src/Rail/LambdaRail.php b/packages/php/src/Rail/LambdaRail.php new file mode 100644 index 00000000..4e73fb3e --- /dev/null +++ b/packages/php/src/Rail/LambdaRail.php @@ -0,0 +1,18 @@ + 6])); + $lambdaRail = new LambdaRail($job, $ipStrategy, $driver); + $lambdaRail->pipe(function (Ip $ip, ?Throwable $exception) use ($driver, $resultNumber, $resultException) { + $driver->stop(); + self::assertSame(ArrayObject::class, $ip->getData()::class); + self::assertSame($resultNumber, $ip->getData()['number']); + self::assertSame($resultException, $exception); + }); + ($lambdaRail)($ip); + + $driver->run(); + } + + /** + * @return array + */ + public function jobProvider(): array + { + return $this->matrix([ + 'job' => [static function (callable $function): Closure { + return static function (ArrayObject $data) use ($function) { + if($data['number'] > 1) { + $calcData = new ArrayObject(['number' => $data['number'] - 1]); + $function($calcData); + $data['number'] = $data['number'] * $calcData['number']; + } else { + $data['number'] = 1; + } + }; + }, 720, null], + ]); + } +} From 62bdfcf6464babd88fd9033c870b1abf63c88ec3 Mon Sep 17 00:00:00 2001 From: Mathieu Ledru Date: Mon, 15 Nov 2021 20:41:45 +0100 Subject: [PATCH 2/2] :memo: add ressources --- .../en/docs/getting-started/changelog.md | 4 ++++ .../en/docs/getting-started/ressources.md | 21 +++++++++++++------ package.json | 4 ++-- packages/php/.gitignore | 1 + packages/php/.php-cs-fixer.cache | 1 - packages/php/composer.json | 2 +- packages/symfony/composer.json | 2 +- 7 files changed, 24 insertions(+), 11 deletions(-) delete mode 100644 packages/php/.php-cs-fixer.cache diff --git a/docs/content/en/docs/getting-started/changelog.md b/docs/content/en/docs/getting-started/changelog.md index 05c49bb5..7aa663c6 100644 --- a/docs/content/en/docs/getting-started/changelog.md +++ b/docs/content/en/docs/getting-started/changelog.md @@ -13,6 +13,10 @@ weight: 60 toc: true --- +### 1.0.9 + +- Add RFBP\Rail\LambdaRail that allows introduce recursivity into Railway-FBP language approach. + ### 1.0.8 - Add code of conduct diff --git a/docs/content/en/docs/getting-started/ressources.md b/docs/content/en/docs/getting-started/ressources.md index 4acf7e38..1d6af27e 100644 --- a/docs/content/en/docs/getting-started/ressources.md +++ b/docs/content/en/docs/getting-started/ressources.md @@ -51,13 +51,22 @@ Video of this project : [https://www.youtube.com/watch?v=mxxdhGsaIjY](https://ww - Why monads are useful : [https://jameswestby.net/tech/why-monads-are-useful.html](https://jameswestby.net/tech/why-monads-are-useful.html) - Promise is neither a Functor nor an Applicative nor a Monad [https://stackoverflow.com/questions/45712106/why-are-promises-monads](https://stackoverflow.com/questions/45712106/why-are-promises-monads) - Monads and Monoids : [https://bartoszmilewski.com/2017/09/06/monads-monoids-and-categories](https://bartoszmilewski.com/2017/09/06/monads-monoids-and-categories) -- go mad for monads : [https://www.youtube.com/watch?v=F5fUgXFSH0Q](https://www.youtube.com/watch?v=F5fUgXFSH0Q) -- functional PHP : [https://www.youtube.com/watch?v=M3_xnTK6-pA](https://www.youtube.com/watch?v=M3_xnTK6-pA) +- Go mad for monads : [https://www.youtube.com/watch?v=F5fUgXFSH0Q](https://www.youtube.com/watch?v=F5fUgXFSH0Q) +- Functional PHP : [https://www.youtube.com/watch?v=M3_xnTK6-pA](https://www.youtube.com/watch?v=M3_xnTK6-pA) - Douglas Crockford: Monads and Gonads : [https://www.youtube.com/watch?v=dkZFtimgAcM](https://www.youtube.com/watch?v=dkZFtimgAcM) -- Monad PHP [https://github.com/ircmaxell/monad-php](https://github.com/ircmaxell/monad-php) -- PHP-Option [https://github.com/schmittjoh/php-option](https://github.com/schmittjoh/php-option) -- Result-Type [https://github.com/GrahamCampbell/Result-Type](https://github.com/GrahamCampbell/Result-Type) -- Functional [https://github.com/whsv26/functional](https://github.com/whsv26/functional) +- Monoids view as Matematical theory for Monads : [https://en.wikipedia.org/wiki/Monoid](https://en.wikipedia.org/wiki/Monoid) +- Lamphpda : [https://github.com/marcosh/lamphpda](https://github.com/marcosh/lamphpda) +- Errors and monads in PHP by [Baptiste LANGLADE](https://twitter.com/Baptouuuu): video [https://www.youtube.com/watch?v=YfoLM0vWALM](https://www.youtube.com/watch?v=YfoLM0vWALM), Github : [https://github.com/Innmind/Immutable](https://github.com/Innmind/Immutable) +- Functional : [https://github.com/whsv26/functional](https://github.com/whsv26/functional) +- Monad PHP : [https://github.com/ircmaxell/monad-php](https://github.com/ircmaxell/monad-php) +- PHP-Option : [https://github.com/schmittjoh/php-option](https://github.com/schmittjoh/php-option) +- Result-Type : [https://github.com/GrahamCampbell/Result-Type](https://github.com/GrahamCampbell/Result-Type) + +## Y-Combinator and PHP +- [Lambda Calculus - Wikipedia](http://en.wikipedia.org/wiki/Lambda_calculus) +- Lambda calculus language explanation : [https://tgdwyer.github.io/lambdacalculus](https://tgdwyer.github.io/lambdacalculus) +- Combinator : [https://github.com/loophp/combinator](https://github.com/loophp/combinator) +- Lambda-php : [https://github.com/igorw/lambda-php](https://github.com/igorw/lambda-php) ## Messaging approach with East oriented code from [Frédéric Hardy](https://twitter.com/mageekguy) - Article : [http://blog.est.voyage/phpTour2015](http://blog.est.voyage/phpTour2015) diff --git a/package.json b/package.json index dacb15af..133d2e1e 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "Railway FBP", "author": { "name": "Mathieu Ledru", - "email": "matyo91@gmail.com" + "email": "matyo91@darkwood.fr" }, "bugs": { "url": "https://github.com/darkwood-fr/railway-fbp" @@ -12,7 +12,7 @@ "keywords": [ "railway-fbp" ], - "version": "1.0.8", + "version": "1.0.9", "browserslist": [ "defaults" ], diff --git a/packages/php/.gitignore b/packages/php/.gitignore index fa4ec64c..e865b7cd 100644 --- a/packages/php/.gitignore +++ b/packages/php/.gitignore @@ -1,4 +1,5 @@ /.phpunit.result.cache +/.php-cs-fixer.cache /.php_cs.cache /build/ /composer.lock diff --git a/packages/php/.php-cs-fixer.cache b/packages/php/.php-cs-fixer.cache deleted file mode 100644 index 76188cb3..00000000 --- a/packages/php/.php-cs-fixer.cache +++ /dev/null @@ -1 +0,0 @@ -{"php":"8.0.3","version":"3.0.0:v3.0.0#c15377bdfa8d1ecf186f1deadec39c89984e1167","indent":" ","lineEnding":"\n","rules":{"array_syntax":true,"backtick_to_shell_exec":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["return"]},"braces":{"allow_single_line_anonymous_class_with_empty_body":true,"allow_single_line_closure":true},"cast_spaces":true,"class_attributes_separation":{"elements":{"method":"one"}},"class_definition":{"single_line":true},"clean_namespace":true,"concat_space":true,"echo_tag_syntax":true,"fully_qualified_strict_types":true,"function_typehint_space":true,"general_phpdoc_tag_rename":{"replacements":{"inheritDocs":"inheritDoc"}},"include":true,"increment_style":true,"lambda_not_used_import":true,"linebreak_after_opening_tag":true,"magic_constant_casing":true,"magic_method_casing":true,"method_argument_space":{"on_multiline":"ignore"},"native_function_casing":true,"native_function_type_declaration_casing":true,"no_alias_language_construct_call":true,"no_alternative_syntax":true,"no_binary_string":true,"no_blank_lines_after_phpdoc":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_extra_blank_lines":{"tokens":["case","continue","curly_brace_block","default","extra","parenthesis_brace_block","square_brace_block","switch","throw","use","use_trait"]},"no_leading_namespace_whitespace":true,"no_mixed_echo_print":true,"no_multiline_whitespace_around_double_arrow":true,"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_around_offset":true,"no_superfluous_phpdoc_tags":{"allow_mixed":true,"allow_unused_params":true},"no_trailing_comma_in_list_call":true,"no_trailing_comma_in_singleline_array":true,"no_unneeded_control_parentheses":{"statements":["break","clone","continue","echo_print","return","switch_case","yield","yield_from"]},"no_unneeded_curly_braces":{"namespaces":true},"no_unset_cast":true,"no_unused_imports":true,"no_whitespace_before_comma_in_array":true,"normalize_index_brace":true,"object_operator_without_whitespace":true,"ordered_imports":true,"php_unit_fqcn_annotation":true,"php_unit_method_casing":true,"phpdoc_align":true,"phpdoc_annotation_without_dot":true,"phpdoc_indent":true,"phpdoc_inline_tag_normalizer":true,"phpdoc_no_access":true,"phpdoc_no_alias_tag":true,"phpdoc_no_package":true,"phpdoc_no_useless_inheritdoc":true,"phpdoc_return_self_reference":true,"phpdoc_scalar":true,"phpdoc_separation":true,"phpdoc_single_line_var_spacing":true,"phpdoc_summary":true,"phpdoc_tag_type":{"tags":{"inheritDoc":"inline"}},"phpdoc_to_comment":true,"phpdoc_trim":true,"phpdoc_trim_consecutive_blank_line_separation":true,"phpdoc_types":true,"phpdoc_types_order":{"null_adjustment":"always_last","sort_algorithm":"none"},"phpdoc_var_without_name":true,"protected_to_private":true,"semicolon_after_instruction":true,"single_class_element_per_statement":true,"single_line_comment_style":{"comment_types":["hash"]},"single_line_throw":true,"single_quote":true,"single_space_after_construct":true,"space_after_semicolon":{"remove_in_empty_for_expressions":true},"standardize_increment":true,"standardize_not_equals":true,"switch_continue_to_break":true,"trailing_comma_in_multiline":true,"trim_array_spaces":true,"unary_operator_spaces":true,"visibility_required":true,"whitespace_after_comma_in_array":true,"yoda_style":true,"blank_line_after_opening_tag":true,"compact_nullable_typehint":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"return_type_declaration":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"blank_line_after_namespace":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"declare_strict_types":true},"hashes":{"tests\/Driver\/ReactDriverTest.php":1314846942,"tests\/Driver\/SwooleDriverTest.php":3204683938,"tests\/Driver\/AmpDriverTest.php":903136282,"tests\/Driver\/DriverTest.php":1767942336,"tests\/Rail\/SequenceRailTest.php":3149521665,"tests\/Rail\/RailTest.php":3175929079,"tests\/Rail\/AbstractRailTest.php":524762452,"tests\/Rail\/ErrorRailTest.php":2954082524,"tests\/IpStrategy\/MaxIpStrategyTest.php":1201133806,"tests\/IpStrategy\/StackIpStrategyTest.php":902801073,"tests\/IpStrategy\/LinearIpStrategyTest.php":223965810,"examples\/rail.php":3453404231,"src\/RailInterface.php":3282409468,"src\/IpStrategyInterface.php":2761416584,"src\/Driver\/SwooleDriver.php":1095035960,"src\/Driver\/ReactDriver.php":3622445700,"src\/Driver\/AmpDriver.php":988422511,"src\/Ip.php":1678591593,"src\/Rail\/SequenceRail.php":17326792,"src\/Rail\/ErrorRail.php":2149132619,"src\/Rail\/RailDecorator.php":1209219207,"src\/Rail\/Rail.php":476937490,"src\/DriverInterface.php":3642445096,"src\/IpStrategy\/LinearIpStrategy.php":231347124,"src\/IpStrategy\/StackIpStrategy.php":1046569492,"src\/IpStrategy\/MaxIpStrategy.php":1171567732}} \ No newline at end of file diff --git a/packages/php/composer.json b/packages/php/composer.json index badf1d93..62040dd1 100644 --- a/packages/php/composer.json +++ b/packages/php/composer.json @@ -6,7 +6,7 @@ "authors": [ { "name": "Mathieu Ledru", - "email": "matyo91@gmail.com" + "email": "matyo91@darkwood.fr" } ], "keywords": [ diff --git a/packages/symfony/composer.json b/packages/symfony/composer.json index 1aa99e92..c993dce2 100644 --- a/packages/symfony/composer.json +++ b/packages/symfony/composer.json @@ -6,7 +6,7 @@ "authors": [ { "name": "Mathieu Ledru", - "email": "matyo91@gmail.com" + "email": "matyo91@darkwood.fr" } ], "keywords": [