php-standard-library/fun
Functional programming utilities for PHP: compose and pipe callables, decorate functions, and control execution (memoize, throttle, debounce, retry, etc.). Part of PHP Standard Library with focused, reusable helpers for cleaner functional-style code.
Feature Development:
pipe($data, parse(), validate(), transform())), cutting development time for data-heavy features.event()->then(notify())->then(archive())), improving readability in Laravel’s event system.retry() for external API calls) without manual retry logic.Roadmap Alignment:
collect(), tap()), reducing fragmentation in the codebase.Build vs. Buy:
Closure chains with a maintained, typed library.Use Cases:
Fun::pipe($request, auth(), validate(), rateLimit())).Fun::pipe($csv, parse(), filter(), map())).Fun::mock()->then(assert())).if-else chains in controllers with Fun::match()).Fun::race($apiCall, $fallback)) for Lambda functions.Adopt if:
collect(), tap(), or closures heavily).if-else or procedural spaghetti.Look elsewhere if:
reactphp or amp instead).Illuminate\Pipeline) for middleware and already have a functional workflow.For Executives: *"This package lets us build backend logic like LEGO blocks—composing functions instead of writing nested conditionals or repetitive middleware. For example, instead of manually chaining auth, validation, and logging in a controller, we’d write:
$response = Fun::pipe($request, auth(), validate(), log(), process());
This cuts development time by 30–50% for repetitive patterns (like API request handling or data transformations) while making the code easier to maintain and test. It’s a lightweight, MIT-licensed tool that aligns with Laravel’s direction toward functional programming—think of it as ‘copy-paste-free’ utilities for PHP. Let’s pilot it in [Feature X] to see how it reduces our utility class sprawl."*
For Engineering (Tech Leads/Architects): *"Fun gives us battle-tested functional utilities to:
Fun::decorate($service, cache(), retry())).Fun::pipe($data, parse(), validate(), serialize())).Fun::retry($apiCall, 3)).
It’s Laravel-friendly, integrates with the container, and avoids the bloat of Symfony/ReactPHP. Let’s prototype it in [Y feature] to compare it against our current ad-hoc Closure chains. If it reduces our utility class count by 20%, it’s a win."*For Developers:
*"No more writing the same try-catch-retry or if-then-else logic everywhere. This package gives you:
// Before: Manual retry logic
function callWithRetry($fn, $maxAttempts) { ... }
// After: One-liner
$retryable = Fun::retry(fn() => $api->call(), 3);
// Before: Nested middleware
$middleware = new LogMiddleware(new AuthMiddleware($next));
// After: Composable pipeline
$middleware = Fun::pipe($request, auth(), log(), $next);
It’s like Lodash for PHP functions—just drop it in and start composing. Perfect for:
How can I help you explore Laravel packages today?