Weave Code
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

Cartesian Product Laravel Package

bentools/cartesian-product

Generate the cartesian product (all combinations) from a multidimensional array with a low-memory iterator. Supports dynamic values via closures that can inspect the partial combination. Iterate results or dump them to an array when needed.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Dynamic Product Configuration: Enable real-time generation of product variants, bundles, or pricing tiers based on combinatorial rules (e.g., e-commerce platforms, SaaS feature matrices).
  • Rule Engines & Workflows: Build scalable rule-based systems where outcomes depend on combinations of inputs (e.g., fraud detection, approval workflows, or dynamic pricing algorithms).
  • A/B Testing & Experimentation: Automate the generation of test scenarios for multi-variate experiments (e.g., UI variants, feature flag permutations) without manual enumeration.
  • Data Transformation Pipelines: Streamline ETL processes where records must be combined or transformed based on multiple attributes (e.g., generating synthetic datasets for analytics).
  • Build vs. Buy: Replace custom recursive or nested-loop implementations with a maintained, optimized solution, reducing technical debt and improving reliability.
  • Roadmap Acceleration: Prioritize features requiring combinatorial logic (e.g., AI-generated content variants, personalized recommendations, or dynamic form generators).
  • Performance Optimization: Replace inefficient custom solutions in high-traffic Laravel APIs or batch jobs (e.g., generating report combinations or cache keys).

When to Consider This Package

  • Adopt if:

    • You need to generate all possible combinations of multi-dimensional arrays (e.g., product attributes, user preferences, or test cases).
    • Your use case involves conditional logic based on combinations (e.g., "If X and Y, apply Z"), leveraging the filter() method.
    • You require low-memory iterative generation (e.g., for large datasets where pre-loading all combinations is infeasible).
    • Your team lacks expertise in combinatorial algorithms, and you want to avoid reinventing the wheel.
    • You’re using PHP 8.2+ and Laravel, and the package’s fluent API aligns with your codebase’s style.
    • You need to count combinations without generating them (e.g., for performance estimation or validation).
  • Look elsewhere if:

    • Your combinations are infinite or unbounded (e.g., streaming data or probabilistic sampling).
    • You need parallel/distributed computation (this package is single-threaded).
    • Your input dimensions are extremely large (e.g., >10^7 combinations), as memory/performance tradeoffs may become prohibitive.
    • You’re working with non-array iterables that don’t implement \Countable (e.g., custom generators without size hints).
    • You require stateful dependencies between combinations (e.g., where later choices depend on prior ones in a non-functional way).
    • You’re using PHP < 8.2 (minimum requirement).
    • You prefer functional programming paradigms (e.g., lazy evaluation, monads) over iterative/array-based approaches.
  • Avoid if:

    • You need probabilistic sampling (e.g., Monte Carlo simulations) instead of exhaustive generation.
    • Your use case involves complex dependencies between dimensions (e.g., hierarchical or graph-based relationships).
    • You’re constrained by legacy PHP versions (<8.2) or environments with limited memory (e.g., shared hosting).

How to Pitch It (Stakeholders)

For Executives: *"This package eliminates the need to manually code complex combinatorial logic—saving development time and reducing bugs. For example, if we’re building a dynamic product configurator (like a car customization tool with 5 options each having 3 variants), it can instantly generate all 243 possible combinations without custom code. This enables faster feature delivery for use cases like:

  • Personalized recommendations (e.g., 'Users with X and Y preferences also liked Z').
  • A/B testing (e.g., automatically generating test scenarios for multi-variate experiments).
  • Dynamic pricing (e.g., calculating discounts based on bundled features). It’s lightweight, actively maintained, and integrates seamlessly with our Laravel stack—reducing technical debt while accelerating innovation."*

For Engineers: *"A high-performance, memory-efficient solution for generating Cartesian products in PHP 8.2+. Key benefits:

  • Lazy evaluation: Generates combinations iteratively (avoids memory overload for large datasets).
  • Flexible filtering/mapping: Use filter() to exclude invalid combinations or each() to transform results (e.g., into Eloquent models).
  • Dynamic values: Supports closures for conditional logic (e.g., 'If hair is black, set eyes to brown').
  • Laravel-friendly: Works alongside Collections, Jobs, and caching layers (e.g., pre-generate combinations for APIs).
  • Performance: Handles millions of combinations efficiently (e.g., 9.7M combos in 1.6s on a mid-range machine). Use it to replace nested loops or recursive functions—ideal for config generators, rule engines, or data pipelines. Example:
// Generate all product variants for an e-commerce bundle
$variants = combinations([
    'color' => ['red', 'blue'],
    'size' => ['S', 'M', 'L'],
])->each(fn($combo) => new ProductVariant($combo));
```*
**For Product Managers**:
*"This tool lets us ship features faster by automating combinatorial logic. For example:
- **Dynamic forms**: Generate all valid field combinations for user inputs.
- **Content personalization**: Create tailored experiences based on user attribute combinations.
- **Reporting**: Automate multi-criteria analysis without manual SQL joins.
It’s a force multiplier for teams building scalable, data-driven products."*
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor