camspiers/php-fp
Composer 安装命令:
composer require camspiers/php-fp
包简介
Functional Programming Helpers
README 文档
README
Currying
A curryable function returns a new function when called with less arguments than the curryable function requires. The new function returned will have the arguments applied, and will also be a curryable function.
This programming pattern can be used to build up more complex functions from less complex functions.
e.g.
// Create a curryable function $concat = fp\curry(function ($a, $b) { return $a . $b; }); // Create a new function with 'Mr. ' applied $addTitle = $concat('Mr. '); echo $addTitle('Spiers'); // Mr. Spiers
Composition
$h = fp\compose($f, $g);
Function composition will return a new function ($h) which will first apply the second function ($g), pass its
result into the first ($f).
Usage
Turning normal functions into curryable functions
$map = fp\curry('array_map');
Create non-closure functions that are curryable
function _tag($tag, $text) { return "<$tag>$text</$tag>"; } function tag(...$args) { return fp\curry('_tag')->__invoke(...$args); } // We now have a paragraph function $p = tag('p'); // We now have a div function $div = tag('div'); echo $div($p("Some text")); // <div><p>Some text</p></div>
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 17
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-08-10