xenira / iter-tools
用于简化PHP中迭代器模式的库
v0.1.0
2023-09-09 03:51 UTC
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.3
- squizlabs/php_codesniffer: ^3.7
This package is auto-updated.
Last update: 2024-09-07 21:09:32 UTC
README
目录一个简单的PHP库,让使用迭代器更加有趣。
受Rust迭代器的极大启发。
目前并非所有方法都已实现,但最重要的都已包括。请谨慎使用。
1. 使用方法
$iterator = new ArrayIterator([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); $iterator = $iterator ->filter(fn ($value) => $value % 2 === 0) ->map(fn ($value) => $value * 2) ->take(4); assert($iterator->collect() === [4, 8, 12, 16]);