bbujisic / functional
Yet another take on functional primitives for PHP
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/bbujisic/functional
Requires (Dev)
This package is auto-updated.
Last update: 2025-12-22 02:26:36 UTC
README
Nothing special. It just adds a little bit of syntactic sugar for more expressive code.
Example
<?php use bbujisic\functional\Collection; $collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); $sumSquaresOfOddItems = $collection ->filter(function ($x) { return $x % 2 == 0; }) ->map(function ($x) { return $x * $x; }) ->reduce(function($x, $y) { return $x + $y; });
Comparable imperative-style programming would perform a wee bit better, at a cost of lesser readability:
<?php $collection = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; $sumSquaresOfOddItems = 0; foreach ($collection as $item) { if ($item % 2 == 0) { $sumSquaresOfOddItems += $item * $item; } }