1. Go to this page and download the library: Download laiz/laiz-monad library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use function Laiz\Func\f;
use function Laiz\Func\Maybe\Just;
use function Laiz\Func\Maybe\Nothing;
$a = Just(3);
$f = f(function($limit, $a){
return $limit > $a ? Just($a) : Nothing();
});
$f2 = $f(2);
$f4 = $f(4);
var_dump($a->bind($f2));
// Nothing
var_dump($a->bind($f4));
// Just 3
use function Laiz\Func\Monad\ret;
use function Laiz\Func\Maybe\Just;
$monad = ret("Foo");
var_dump($monad->mappend([]));
// ['Foo']
var_dump($monad->mappend("Bar"));
// 'FooBar'
var_dump($monad->mappend(Just("Baz")));
// Just 'FooBaz'
var_dump($monad->mplus(Just("Baz")));
// Just 'Foo'
use function Laiz\Func\f;
use function Laiz\Func\Functor\fmap;
use function Laiz\Func\Functor\fconst;
use function Laiz\Func\Monoid\mappend;
use function Laiz\Func\MonadZero\guard;
use function Laiz\Func\Maybe\fromMaybe;
// (integer d, Functor s, MonadPlus s) => d -> a -> d -> s a
function calc(...$args){
return f(function($d, $s, $n){
return fconst($s, guard($n % $d === 0));
}, ...$args);
}
$fizzbuzz = fromMaybe()->ap(mappend(calc(3, "Fizz"), calc(5, "Buzz")));
function pr(...$args){
return f(function($a){
echo $a, "\n";
return $a;
}, ...$args);
}
$ret = fmap(pr()->compose($fizzbuzz), range(1, 100));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.