headsnet/collections
最新稳定版本:v0.2.1
Composer 安装命令:
composer require headsnet/collections
包简介
Base classes for collections
关键字:
README 文档
README
Headsnet Collections
Installation
composer require headsnet/collections
Usage
Assuming you have some class Foo that you want to put into a collection:
final class Foo { public function __construct( public string $name ) { } }
Then create a custom named collection to hold the Foo instances:
/** * @extends AbstractImmutableCollection<Foo> * * @method self filter(callable $func) * @method self reverse() */ final class FooCollection extends AbstractImmutableCollection { public function getItemClassName(): string { return Foo::class; } }
Then instantiate the collection:
$foo1 = new Foo(); $foo2 = new Foo(); $allFoos = new FooCollection([$foo1, $foo2]);
You then have an immutable, iterable object that can be filtered, mapped and walked:
foreach ($allFoos as $foo) { $this->assertInstanceOf(Foo::class, $foo); }
Contributing
Contributions are welcome. Please submit pull requests with one fix/feature per pull request.
统计信息
- 总下载量: 13.02k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-06-18