Skip to content

Commit

Permalink
Merge pull request #15 from darkwood-fr/lambda-rail
Browse files Browse the repository at this point in the history
✨ Add Lambda Rail
  • Loading branch information
Mathieu Ledru authored Nov 15, 2021
2 parents 6dde211 + f2a44c1 commit 59198af
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 14 deletions.
4 changes: 4 additions & 0 deletions docs/content/en/docs/getting-started/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 15 additions & 6 deletions docs/content/en/docs/getting-started/ressources.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,23 @@ 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)
- Monad PHP [https://github.com/ircmaxell/monad-php](https://github.com/ircmaxell/monad-php)

## 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)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -12,7 +12,7 @@
"keywords": [
"railway-fbp"
],
"version": "1.0.8",
"version": "1.0.9",
"browserslist": [
"defaults"
],
Expand Down
1 change: 1 addition & 0 deletions packages/php/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.phpunit.result.cache
/.php-cs-fixer.cache
/.php_cs.cache
/build/
/composer.lock
Expand Down
1 change: 0 additions & 1 deletion packages/php/.php-cs-fixer.cache

This file was deleted.

5 changes: 3 additions & 2 deletions packages/php/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"authors": [
{
"name": "Mathieu Ledru",
"email": "matyo91@gmail.com"
"email": "matyo91@darkwood.fr"
}
],
"keywords": [
Expand All @@ -17,7 +17,8 @@
"monad"
],
"require": {
"php": "^8.0"
"php": "^8.0",
"loophp/combinator": "^2.0"
},
"require-dev": {
"amphp/amp": "^2.6",
Expand Down
4 changes: 2 additions & 2 deletions packages/php/src/Driver/ReactDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
18 changes: 18 additions & 0 deletions packages/php/src/Rail/LambdaRail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace RFBP\Rail;

use Closure;
use loophp\combinator\Combinators;
use RFBP\DriverInterface;
use RFBP\IpStrategyInterface;

class LambdaRail extends RailDecorator
{
public function __construct(Closure $job, ?IpStrategyInterface $ipStrategy = null, ?DriverInterface $driver = null)
{
parent::__construct(new Rail(Combinators::Y()($job), $ipStrategy, $driver));
}
}
54 changes: 54 additions & 0 deletions packages/php/tests/Rail/LambdaRailTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace RFBP\Test\Rail;

use ArrayObject;
use Closure;
use RFBP\DriverInterface;
use RFBP\Ip;
use RFBP\IpStrategyInterface;
use RFBP\Rail\LambdaRail;
use Throwable;

class LambdaRailTest extends AbstractRailTest
{
/**
* @dataProvider jobProvider
*/
public function testJob(DriverInterface $driver, IpStrategyInterface $ipStrategy, Closure $job, int $resultNumber, ?Throwable $resultException): void
{
$ip = new Ip(new ArrayObject(['number' => 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<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],
]);
}
}
2 changes: 1 addition & 1 deletion packages/symfony/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"authors": [
{
"name": "Mathieu Ledru",
"email": "matyo91@gmail.com"
"email": "matyo91@darkwood.fr"
}
],
"keywords": [
Expand Down

0 comments on commit 59198af

Please sign in to comment.