phlak / collection
0.1.0
2017-09-04 07:33 UTC
Requires
- php: >=5.6
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.3
- phpunit/phpunit: ^5.7
This package is auto-updated.
Last update: 2019-11-07 05:27:22 UTC
README
轻量级集合库 -- 由,Chris Kankiewicz
需求
- PHP >= 5.6
使用 Composer 安装
composer require phlak/collection
初始化客户端
首先,导入 Collection
use PHLAK\Collection;
然后传递一个项目数组给 Collection 类或静态的 make 方法
$collection = new Collection\Collection(['foo', 'bar', 'baz']); // or $collection = Collection\Collection::make(['foo', 'bar', 'baz']);
使用方法
遍历集合中的每个项目,并通过闭包执行一个动作
$collection->each(Closure $function);
通过闭包将集合中的每个项目映射到一个新值
$collection->map(Closure $function);
通过闭包返回 true 的项目来过滤集合中的项目
$collection->filter(Closure $function);
通过闭包返回 false 的项目来过滤集合中的项目(filter 方法的相反操作)
$collection->reject(Closure $function);
通过迭代闭包直到只剩下一个项目来减少集合到单个项目
$collection->reduce(Closure $function, $initial);
计算集合中所有项目的总和并返回值
$collection->sum(Closure $function, $initial);
变更日志
可以在 GitHub Releases 页面上找到更改列表。
故障排除
请向 GitHub Issue Tracker 报告错误。
版权
此项目在 MIT 许可证 下发布。