hampom / bari-kata-functional
0.0.1
2025-09-15 02:26 UTC
Requires
- php: >=8.2
- hampom/bari-kata: 0.0.1
Requires (Dev)
- carthage-software/mago: 1.0.0-beta.14
- dg/bypass-finals: ^1.9
- phpunit/phpunit: ^12
This package is not auto-updated.
Last update: 2025-09-16 01:04:14 UTC
README
https://github.com/hampom/BariKata のプラグイン集です
プラグイン
- FilterPlugin
- MapPlugin
- ReducePlugin
インストール
Composer を使ってインストールできます
composer require hampom/barikata-functional
使い方
基本的な使い方の例をいくつか示します
FilterPlugin
$collection = new TypedCollection('int', [1, 2, 3, 4, 5], [ new FilterPlugin() ]); $results = $collection->filter(fn(int $x) => $x % 2 === 0); // -> [2, 4]
MapPlugin
$collection = new TypedCollection('int', [1, 2, 3, 4, 5], [ new MapPlugin() ]); $results = $collection->map(fn(int $x) => $x * 2); // -> [2, 4, 6, 8, 10]
ReducePlugin
$collection = new TypedCollection('int', [1, 2, 3, 4, 5], [ new ReducePlugin() ]); $results = $collection->reduce(fn(int $carry, int $x) => $carry + $x, 0); // -> 15