chore: Аннотации к типам
This commit is contained in:
parent
89913de4fe
commit
386a927254
6 changed files with 63 additions and 27 deletions
|
|
@ -62,8 +62,12 @@ class partial {
|
|||
$this->params = $params;
|
||||
}
|
||||
|
||||
function apply() {
|
||||
$params = func_get_args();
|
||||
/**
|
||||
* Применение функции
|
||||
* @param mixed ...$params
|
||||
* @return mixed
|
||||
*/
|
||||
function apply(...$params) {
|
||||
$result = [];
|
||||
$count = count($this->params);
|
||||
for($i = 0, $j = 0; $i < $count; $i++) {
|
||||
|
|
@ -87,8 +91,12 @@ class compose {
|
|||
$this->fns = array_reverse($list);
|
||||
}
|
||||
|
||||
function apply () {
|
||||
$params = func_get_args ();
|
||||
/**
|
||||
* Применение функций
|
||||
* @param mixed ...$params
|
||||
* @return mixed
|
||||
*/
|
||||
function apply (...$params) {
|
||||
$result = call_user_func_array($this->fns[0], $params);
|
||||
$count = count($this->fns);
|
||||
for ($i = 1; $i < $count; $i++) {
|
||||
|
|
@ -100,39 +108,44 @@ class compose {
|
|||
|
||||
class Functions {
|
||||
|
||||
static function partial($_rest) {
|
||||
$closure = new partial(func_get_args());
|
||||
/**
|
||||
* Частичное применение функции
|
||||
* @param mixed ...$args
|
||||
* @return mixed
|
||||
*/
|
||||
static function partial(...$args) {
|
||||
$closure = new partial($args);
|
||||
return [$closure, 'apply'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Композиция функций
|
||||
* @param array $_rest
|
||||
* @param mixed ...$args
|
||||
* @return mixed
|
||||
*/
|
||||
static function compose($_rest) {
|
||||
$closure = new compose(func_get_args());
|
||||
static function compose(...$args) {
|
||||
$closure = new compose($args);
|
||||
return [$closure, 'apply'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Карирование справа
|
||||
*
|
||||
* @param mixed ...$args
|
||||
* @return mixed
|
||||
*/
|
||||
static function rcurry($_rest) {
|
||||
$closure = new right(func_get_args ());
|
||||
static function rcurry(...$args) {
|
||||
$closure = new right($args);
|
||||
return [$closure, 'apply'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Карирование слева
|
||||
*
|
||||
* @param mixed ...$args
|
||||
* @return mixed
|
||||
*/
|
||||
static function lcurry($_rest) {
|
||||
$closure = new left(func_get_args ());
|
||||
static function lcurry(...$args) {
|
||||
$closure = new left($args);
|
||||
return [$closure, 'apply'];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue