nikic/iter
Composer 安装命令:
composer require nikic/iter
包简介
Iteration primitives using generators
README 文档
README
This library implements iteration primitives like map() and filter()
using generators. To a large part this serves as a repository for small
examples of generator usage, but of course the functions are also practically
quite useful.
All functions in this library accept arbitrary iterables, i.e. arrays,
traversables, iterators and aggregates, which makes it quite different from
functions like array_map() (which only accept arrays) and the SPL iterators
(which usually only accept iterators, not even aggregates). The operations are
of course lazy.
Install
To install with composer:
composer require nikic/iter
Functionality
A small usage example for the map() and range() functions:
<?php use iter\func; require 'path/to/vendor/autoload.php'; $nums = iter\range(1, 10); $numsTimesTen = iter\map(func\operator('*', 10), $nums); // => iter(10, 20, 30, 40, 50, 60, 70, 80, 90, 100)
You can find documentation and usage examples for the individual functions in iter.php, here I only list the function signatures as an overview:
Iterator map(callable $function, iterable $iterable)
Iterator mapWithKeys(callable $function, iterable $iterable)
Iterator mapKeys(callable $function, iterable $iterable)
Iterator flatMap(callable $function, iterable $iterable)
Iterator reindex(callable $function, iterable $iterable)
Iterator filter(callable $predicate, iterable $iterable)
Iterator enumerate(iterable $iterable)
Iterator toPairs(iterable $iterable)
Iterator fromPairs(iterable $iterable)
Iterator reductions(callable $function, iterable $iterable, mixed $startValue = null)
Iterator zip(iterable... $iterables)
Iterator zipKeyValue(iterable $keys, iterable $values)
Iterator chain(iterable... $iterables)
Iterator product(iterable... $iterables)
Iterator slice(iterable $iterable, int $start, int $length = INF)
Iterator take(int $num, iterable $iterable)
Iterator drop(int $num, iterable $iterable)
Iterator takeWhile(callable $predicate, iterable $iterable)
Iterator dropWhile(callable $predicate, iterable $iterable)
Iterator keys(iterable $iterable)
Iterator values(iterable $iterable)
Iterator flatten(iterable $iterable, int $levels = INF)
Iterator flip(iterable $iterable)
Iterator chunk(iterable $iterable, int $size, bool $preserveKeys = false)
Iterator chunkWithKeys(iterable $iterable, int $size)
Iterator tap(callable $function, iterable $iterable)
Iterator toIter(iterable $iterable)
Iterator range(number $start, number $end, number $step = null)
Iterator repeat(mixed $value, int $num = INF)
Iterator split(string $separator, string $data)
mixed reduce(callable $function, iterable $iterable, mixed $startValue = null)
bool any(callable $predicate, iterable $iterable)
bool all(callable $predicate, iterable $iterable)
mixed search(callable $predicate, iterable $iterable)
void apply(callable $function, iterable $iterable)
string join(string $separator, iterable $iterable)
int count(iterable $iterable)
bool isEmpty(iterable $iterable)
mixed recurse(callable $function, $iterable)
array toArray(iterable $iterable)
array toArrayWithKeys(iterable $iterable)
bool isIterable($value)
As the functionality is implemented using generators the resulting iterators are by default not rewindable. This library implements additional functionality to allow creating rewindable generators.
You can find documentation for this in iter.rewindable.php, here is just a small usage example of the two main functions:
<?php use iter\func; require 'path/to/vendor/autoload.php'; /* Create a rewindable map function which can be used multiple times */ $rewindableMap = iter\makeRewindable('iter\\map'); $res = $rewindableMap(func\operator('*', 3), [1, 2, 3]); /* Do a rewindable call to map, just once */ $res = iter\callRewindable('iter\\map', func\operator('*', 3), [1, 2, 3]);
The above functions are only useful for your own iterators though; for the
iter iterators, rewindable variants are directly provided with an
iter\rewindable prefix:
$res = iter\rewindable\map(func\operator('*', 3), [1, 2, 3]);
// etc
nikic/iter 适用场景与选型建议
nikic/iter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.41M 次下载、GitHub Stars 达 1.14k, 最近一次更新时间为 2013 年 11 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「iterator」 「functional」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nikic/iter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nikic/iter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nikic/iter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
collection php library
Connection 'Db' codeception module to 'Yii2' module database settings
PHP PDO Mysql select statement iterator implemented as multiple queries using LIMIT clauses
Functional library for php with proper currying
Iteration tools for PHP
统计信息
- 总下载量: 6.41M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1150
- 点击次数: 33
- 依赖项目数: 57
- 推荐数: 1
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2013-11-27