Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Functional Laravel Package

fp4php/functional

fp4php/functional brings functional programming to PHP with immutable collections, pipelines, pattern matching, and composable helpers. It simplifies data transformation and reduces boilerplate while fitting naturally into Laravel and existing PHP codebases.

View on GitHub
Deep Wiki
Context7

PHP Functional Programming library

Frequently asked questions about Functional
What is fp4php/functional used for in a PHP or Laravel codebase?
fp4php/functional is a pure-PHP functional programming toolkit rather than a framework. It provides monadic types such as Option/Maybe, Either, and Try, function combinators like compose, pipe, curry, and memoize, and immutable collections with map, filter, and reduce. It is built to drop into an existing PHP or Laravel app without any runtime coupling. Teams typically use it in domain and service layers where null checks and exception branching are dense, and keep it out of controllers and Blade templates.
How do I install fp4php/functional with Composer?
Install it with composer require fp4php/functional and let Composer resolve the version constraints against your PHP runtime. There is no installer, native extension, or infrastructure requirement, so the Composer step is the whole setup. No service provider registration or config publishing is needed because it is a plain library. Check the package composer.json for the exact PHP constraint before standardizing it across a team codebase.
Is fp4php/functional compatible with Laravel, and which PHP and Laravel versions are supported?
The library is pure PHP with no framework services, so it runs inside Laravel as long as your PHP version satisfies the package constraint. The available documentation does not pin specific PHP or Laravel versions tested in CI, so verify the constraint in composer.json against your platform's supported runtimes. Because it does not hook into the framework, Laravel upgrades are unlikely to be a breaking concern, and the PHP version is the real gate. Confirm this in your own CI matrix before committing.
Do I need to register a service provider or publish config to use fp4php/functional in Laravel?
No. fp4php/functional is a library, not a Laravel package, so there is no service provider, facade, or config file to register or publish. You import the functions and types only in the files that use them. If you want container injection, bind your own thin domain services that use the library and inject those, keeping the rest of the application unaware of it.
How do Option and Either replace null checks and exceptions in Laravel?
Option and Either replace the null-and-exception idiom with explicit, composable return values. Instead of returning null for absence or throwing for expected failures, a service returns Some/None or Right/Left, and callers map over the success path without repeated if checks. The tradeoff is that Laravel itself throws validation exceptions and uses findOrFail, so spreading monads everywhere creates two competing error-handling dialects. The safer pattern is to keep monads inside one bounded context and convert them to plain DTOs or exceptions before crossing into controllers, jobs, and API resources.
Can I return Option, Either, or an immutable collection from a controller, API resource, or queued job?
Do not. Monads are not JSON-serializable and are meant to stay inside the PHP process, so passing them to API resources, Blade views, or queue payloads causes silent bugs. Always unwrap to plain DTOs, scalars, or exceptions at the boundary before returning to controllers, jobs, or responses. Remember that any object is truthy in PHP, so a forgotten wrapper will pass an if check and fail much later.
Does fp4php/functional provide real generics and PHPStan or Psalm support?
PHP has no runtime generics, so the generic collection typing in this package is docblock-level and depends entirely on your static analysis discipline. Whether the package ships PHPStan or Psalm stubs, and at what strictness level, should be confirmed before adoption. If static analysis is not already enforced in CI, much of the type-safety value proposition disappears, so enable a baseline at a meaningful level first.
How do I test code that returns Option, Either, or Try?
Assert on the unwrapped domain result rather than on the wrapper internals. Call the function under test, then extract the value from Some/None, Right/Left, or Success/Failure using the library accessors and assert on that. Cover the failure branches explicitly, because a monad that is returned and never inspected is always truthy and can hide a broken path. Add a static analysis step to CI so the docblock generics on collections are actually verified.
Is fp4php/functional actively maintained and safe to depend on in production?
The signals are mixed. It is MIT licensed with a recent release, which shows some liveness, but a small star count and an unclear repository location suggest a limited maintainer base and low bus factor. Before depending on it, confirm the public issue tracker, release cadence, security disclosure process, and support policy. Treat it as an internal domain tool with a clear exit path rather than a platform standard.
How does fp4php/functional compare to loophp/collection, widmogrod/php-functional, and php-standard-library?
These libraries overlap in scope, and each carries its own idiom and collection contract, so migrating between them means rewriting call sites rather than swapping a dependency. fp4php/functional is lightweight and composable but has a smaller community footprint than the more established options. If you need a broad, well-maintained collection API, compare feature breadth and release cadence first. If you only need Option and Either at a handful of domain boundaries, a minimal toolkit keeps lock-in low.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle