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

th3n3rd/cartesian-product

Memory-efficient Cartesian Product generator for PHP. Uses iterators to yield one tuple at a time, letting you handle very large combinations without big memory usage. Build products via fluent with() calls or CartesianProduct::of(), iterate or toArray().

View on GitHub
Deep Wiki
Context7

Cartesian Product

Latest Version Build Status Software License Total Downloads

Memory efficient Cartesian Product implementation.

It uses iterators in order to store only a specific tuple at a time, being able to compute even large combinations without affecting the memory footprint.

Install

Via Composer

$ composer require th3n3rd/cartesian-product

Usage

The library can be used as an iterator:

use Nerd\CartesianProduct\CartesianProduct;

$cartesianProduct = CartesianProduct::empty()
    ->with(['a', 'b', 'c'])
    ->with(['d', 'e'])
;

// or you can use the `of` static method:
$cartesianProduct = CartesianProduct::of([
    ['a', 'b', 'c'],
    ['d', 'e'],
]);

foreach ($cartesianProduct as $index => $product) {
    printf("[%s] (%s)\n", $index, implode(',', $product));
}

You can also compute the whole result at once (not recommended for large sets):

$result = $cartesianProduct->toArray();

Testing

$ vendor/bin/phpunit

License

The MIT License (MIT). Please see License File for more information.

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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport