定制 nemorize/curried 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nemorize/curried

最新稳定版本:0.0.1

Composer 安装命令:

composer require nemorize/curried

包简介

A utility to create curried functions that its parameters are reordered by user-defined order.

README 文档

README

A utility to create curried functions that its parameters are reordered by user-defined order.
Inspired by https://github.com/andjsrk/create-curried.

Requirements

  • PHP 8.1 or later

Installation

composer require nemorize/curried

Usage

Curried

Curried::from(Closure $fn): Context

Returns a Context for a given closure.

use Nemorize\Curried\Curried;
$context = Curried::from(function ($foo, $bar) {
    return $foo . $bar;
});

Context

Context::takes(int $position): Context

Takes a parameter at the given position.

use Nemorize\Curried\Curried;
$context = Curried::from(function ($foo, $bar) {
    return $foo . $bar;
})->takes(0)->takes(1);

Context::takesRest(): Context

Takes the rest of parameters.

use Nemorize\Curried\Curried;
$context = Curried::from(function ($foo, $bar, $baz) {
    return $foo . $bar . $baz;
})->takes(0)->takesRest();

Context::withStatic(int $position): Closure

Binds a parameter at the given position to the closure.
Returned closure returns a Context for the next parameter.

use Nemorize\Curried\Curried;
$context = Curried::from(function ($foo, $bar) {
    return $foo . $bar;
})->takes(0)->withStatic(1)('bar');

Context::generate(): Closure

Generates a curried function.

use Nemorize\Curried\Curried;
$curried = Curried::from(function ($foo, $bar) {
    return $foo . $bar;
})->takes(0)->takes(1)->generate();
$curried('foo')('bar'); // 'foobar'

Examples

Plus one to each element of an array

use Nemorize\Curried\Curried;
$map = Curried::from(array_map(...))
    ->takes(0)
    ->takes(1)
    ->generate();
$plusOneEach = $map(fn (int $x) => $x + 1);
$plusOneEach([1, 2, 3]); // [2, 3, 4]

Sum of an array

use Nemorize\Curried\Curried;
$sum = Curried::from(array_reduce(...))
    ->takes(1)
    ->withStatic(0)(fn (int $x, int $y) => $x + $y)
    ->generate();
$sum([1, 2, 3]); // 6

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-02-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固