capci/stream
Composer 安装命令:
composer require capci/stream
包简介
Java-like Stream API library for PHP
关键字:
README 文档
README
Java-like Stream API library for PHP.
Intermediate operations are not evaluated until terminal operation is invoked (lazy evaluation).
Requires PHP 7.2 or newer.
Usage
Basic usage.
Stream::of("a", "b", "c", "d", "e", "x")->filter(function ($value) { return $value !== "x"; })->map(function($value) { return strtoupper($value); })->forEach(function ($value) { echo $value . ", "; }); // A, B, C, D, E,
Generate Stream
- from values.
$stream = Stream::of("a", "b", "c");
- from array or Traversable.
$stream = Stream::ofIterable([ "a", "b", "c", ]);
$stream = Stream::ofIterable(new DirectoryIterator("."));
- from generator function.
$stream = Stream::ofGenerator(function () { yield "a"; yield "b"; yield "c"; });
- and others
empty, concat.
Intermediate operation
- filter
$stream = Stream::ofIterable(range(0, 10)); $stream = $stream->filter(function ($value) { return $value > 5; }); // 6 7 8 9 10
- map
$stream = Stream::ofIterable(range(0, 5)); $stream = $stream->map(function ($value) { return $value * 2; }); // 0 2 4 6 8 10
- sorted
$stream = Stream::ofIterable(range(0, 5)); $stream = $stream->sorted(function ($value1, $value2) { return $value2 - $value1; }); // 5 4 3 2 1 0
- and others
flatMap, skip, skipWhile, limit, limitWhile, distinct, peek.
Terminal operation
- forEach
$stream = Stream::ofIterable(range(0, 5)); $stream->forEach(function ($value) { echo $value . ", "; }); // 0, 1, 2, 3, 4, 5,
- toArray
$stream = Stream::ofIterable(range(0, 5)); $array = $stream->toArray(); // [0, 1, 2, 3, 4, 5]
- reduce
$stream = Stream::ofIterable(range(0, 5)); $sum = $stream->reduce(0, function ($accum, $value) { return $accum + $value; }); // 15
- and others
count, allMatch, anyMatch, nonMatch, findFirstOrDefault, findLastOrDefault, maxOrDefault, minOrDefault.
License
MIT
capci/stream 适用场景与选型建议
capci/stream 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 10 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Stream API」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 capci/stream 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 capci/stream 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 capci/stream 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Object-Oriented API for PHP streams
Safely namespaced guzzle psr7 for WP2Static
Interface for a factory to create Psr\Http\Message\StreamInterface objects
A PSR-7 compatible library for making CRUD API endpoints
Implementation of webignition/stream-factory-interface
High-performance PHP library for streaming JSON parsing with constant memory usage.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-14