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

Either Or Both Laravel Package

php-standard-library/either-or-both

A three-variant disjoint union type for PHP. EitherOrBoth models values that may be present on the left, the right, or both sides at once, giving you a type-safe way to express partial successes, asymmetric results, and paired data without nullable workarounds.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Feature Development: Enables modeling complex state machines, validation pipelines, or async workflows where operations may succeed/fail on one or both sides (e.g., dual API calls, database transactions, or distributed systems).
  • Roadmap Alignment: Supports a "build vs. buy" decision for teams needing exhaustive pattern matching (e.g., match expressions in PHP 8.1+) without reinventing union types. Ideal for projects adopting domain-driven design (DDD) or event sourcing.
  • Use Cases:
    • Validation Layers: Replace nested if-else chains for multi-step validation (e.g., "validate user input and permissions").
    • Async/Await Patterns: Model operations where two independent tasks may complete partially (e.g., "fetch user data or cache it or both").
    • Error Handling: Replace try-catch spaghetti for dual-error scenarios (e.g., "API call failed but fallback succeeded").
    • State Machines: Represent states like Left (pending), Right (success), or Both (partial success).

When to Consider This Package

Adopt if:

  • Your team uses PHP 8.1+ (for match expressions) and needs type-safe disjoint unions without heavyweight libraries (e.g., spatie/array-to-object).
  • You’re building systems where dual outcomes are common (e.g., microservices, batch processing, or hybrid sync/async workflows).
  • You prioritize explicit state handling over implicit null checks or array hacks.
  • Your architecture leans toward functional programming (e.g., immutability, pure functions).

Look elsewhere if:

  • You need only binary outcomes (use stdClass or bool flags).
  • Your stack is pre-PHP 8.1 (lacks match support).
  • You’re constrained by dependency bloat (this is a tiny, focused package).
  • You prefer existing solutions like:
    • League\Pipeline (for validation chains).
    • ReactPHP (for async workflows).
    • Custom enum classes (if Both isn’t critical).

How to Pitch It (Stakeholders)

For Executives: "This package lets us model complex, dual-outcome workflows—like validating both user input and permissions—with clean, type-safe code. It’s a lightweight alternative to custom solutions, reducing technical debt in systems where operations may succeed, fail, or partially succeed. Think of it as ‘either/or/both’ for PHP, enabling safer, more maintainable logic in validation, async tasks, and state machines."

For Engineers: *"EitherOrBoth gives us a three-state union type (Left, Right, Both) to replace verbose if-else or array hacks. Key benefits:

  • Type Safety: Exhaustive match expressions catch edge cases.
  • Readability: Self-documenting states (e.g., Both::new($user, $permissions)).
  • Performance: Zero overhead; just a thin wrapper.
  • Future-Proof: Aligns with PHP’s evolving type system.

Example use case: Replace this:

if ($user && $permissions) { ... }

with this:

match ($result) {
    Left::class => handleLeft(),
    Right::class => handleRight(),
    Both::class => handleBoth($result->left(), $result->right()),
};
```*
*Best for teams using PHP 8.1+ and needing to model non-binary outcomes."*
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.
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log