pre/short-closures
Composer 安装命令:
composer require pre/short-closures
包简介
README 文档
README
Documentation can be found at preprocess.io.
Since this RFC was approved, we have standardised on the same syntax. We do still allow function bodies and return type hints, but everything in that RFC can be done, with the same syntax, as far back as Yay will allow (7.1).
You can use closures with similar semantics to Javascript:
$files = array_map( fn($path) => file_get_contents($path), $paths ); $needles = [ "PHP", "Go", "Javascript", ]; $matches = array_filter($files, fn($content = "") => { foreach ($needles as $needle) { if (stristr($content, $needle)) { return true; } } return false; });
These are converted to:
$files = array_map( function ($path) { return file_get_contents($path); }, $paths ); $needles = [ "PHP", "Go", "Javascript", ]; $matches = array_filter($files, [$needles = $needles ?? null, $needle = $needle ?? null, "fn" => function ($content = "") use (&$needles, &$needle) { foreach ($needles as $needle) { if (stristr($content, $needle)) { return true; } } return false; }]["fn"]);
统计信息
- 总下载量: 480
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 35
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-01-27