nonsensecreativity / dash
类似于 LoDash,但适用于 PHP 且更轻量
dev-master
2017-08-20 04:58 UTC
Requires
- php: >=7.1
Requires (Dev)
- atoum/atoum: ^3.1
- atoum/stubs: ^2.5
- phpmd/phpmd: ^2.6
- phpunit/phpunit: ^6.3
This package is not auto-updated.
Last update: 2024-09-29 00:42:13 UTC
README
类似于 LoDash 但更小
注意:至少需要 PHP 版本 7.1
使用方法
composer require nonsensecreativity\dash
导入并调用库的静态方法
use function NSC\Dash\Iterables; /** * All iterable hook always provide * - The current value * - The current key * - The iterable set * * @param int $v * @param int $k * @param iterable $itr * @return iterable */ $flatMap = Iterables::flatMap([1, 2, 3, 4], function(int $v, int $k, iterable $itr) { return [$v + 1, $v]; });
或者使用 dash 静态方法,它将自动将调用方法重定向到正确的类
use NSC\Dash\Dash; Dash::flatMapDeep( ['a', [ 'b', [ 'c', [ 'd' ] ] ] ], function(string $v, int $k, iterable $itr) { return [ $v, $v . ' FLATMAPDEEP' ]; } );
或者使用序列
$seq = Sequence::from([1, [2, [3, [4, 5]]]]); $seq->flatten() ->reverse() ->flatMap(function($v, $k, $iterable) { return [$v, $v]; }) ->result();
待办事项
- 添加测试用例(已添加一些示例)
- 更多功能