λ Functional
Functional programming treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data. It is declarative, which means expressions instead of statements.
Last updated
use Siler\Functional as λ;
$pred = λ\if_else(λ\equal('foo'))(λ\always('is foo'))(λ\always('isnt foo'));
echo $pred('foo'); // is foo
echo $pred('bar'); // isnt foouse Siler\Functional as λ;
$add = function ($a, $b) {
return $a + $b;
};
$add2 = λ\partial($add, 2);
echo $add2(3); // 5use Siler\Functional as λ;
$explodeCommas = λ\partial('explode', ',');
print_r($explodeCommas('foo,bar,baz'));
/**
* Array
* (
* [0] => foo
* [1] => bar
* [2] => baz
* )
*/use Siler\Functional as λ;
$nameOf = λ\match([
[λ\equal(1), λ\always('one')],
[λ\equal(2), λ\always('two')],
[λ\equal(3), λ\always('three')],
]);
echo $nameOf(1); // one
echo $nameOf(2); // two
echo $nameOf(3); // three