rodrigodornelles / php-array-lib
基于数组的简单库,用于函数式编程范式
1.0.0
2022-04-17 13:30 UTC
Requires
- php: ~5.4.0|~5.5.0|~5.6.0|~7.0.0|~7.1.0|~7.2.0|~7.3.0|~7.4.0|~8.0.0|~8.1.0|~8.2.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-28 03:18:16 UTC
README
基于数组的简单库,用于函数式编程范式
特性
- 测试驱动开发风格 (TDD)
- PHP版本兼容性 5.4 至 8.2
- 使您的代码更简洁、更易读
- 添加新的数组操作方法 (灵感来源于 ruby,js 等其他语言)
如何使用
use ArrayCreate; # if you using namespaces $myNewArray = ArrayCreate::from($myOriginalArray) # instantiate pipeline class ->map(someItemFunction) # first function to iterate on each item ->map(anotherItemFunction) # next function to iterate on each item ->filter(anotherItemFunction2) # next function to filter on each item ->construct(); # returns new array
示例
并列比较
编写一个算法,对数组进行排序,移除不能被3整除的数字,并显示每个数字乘以2的结果,并用逗号分隔。
安装
使用Composer
安装此扩展的首选方式是通过 composer。
运行以下命令之一
$ composer require rodrigodornelles/php-array-lib "~1.0.0"
或添加
"rodrigodornelles/php-array-lib": "~1.0.0"
到您的 composer.json
文件的 require
部分。
不使用Composer
第1步
从 https://github.com/RodrigoDornelles/php-array-lib/releases 下载库
第2步
将文件提取到您的库文件夹中
第3步
导入主类
<?php require_once __DIR__.'/path/to/my/libaries/php-array-lib/src/ArrayCreate.php';