pitchart/transformer
最新稳定版本:v1.6.2
Composer 安装命令:
composer require pitchart/transformer
包简介
A transducers implementation in PHP, with OOP powers
README 文档
README
A transducers implementation in PHP, with OOP powers
This package has been inspired by libraries provided by other languages, like clojure's transducers or JAVA Stream API.
Why ?
Transducers are composable algorithmic transformations. They are independent from the context of their input and output sources and specify only the essence of the transformation in terms of an individual element. Because transducers are decoupled from input or output sources, they can be used in many different processes - collections, streams, channels, observables, etc. Transducers compose directly, without awareness of input or creation of intermediate aggregates.
More information on the clojure reference
With classical pipeline pattern, the whole collection is iterated for each step of the transformation and creates an intermediate collection which is a massive waste in memory usage.
Transducers use functional composition to reduce the number of iterations made while applying transformation.
Installation
composer require pitchart/transformer
Usage
A transformation consists in a pipeline of transformation functions, called Reducers, ended by a reducing function, aka Termination.
use function Pitchart\transform; transform([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) ->filter(function (int $integer) { return $integer % 2 === 0;}) // [0, 2, 4, 6, 8, 8, 6, 4, 2, 0] ->map(function (int $integer) { return $integer + 1; }) // [1, 3, 5, 7, 9, 9, 7, 5, 3, 1] ->dedupe() // [1, 3, 5, 7, 9, 9, 7, 5, 3, 1] ->distinct() // [1, 3, 5, 7, 9] ->take(3) // [1, 3, 5] ->sum() // 9 ;
API documentation
"Functional patterns" used by the library are discribed in the Reducers documentation
Credits
Licence
The MIT License (MIT). See License file for more information.
统计信息
- 总下载量: 16.88k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 3
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-07-05