Download the PHP package anarchitecture/combinatorics without Composer
On this page you can find all versions of the php package anarchitecture/combinatorics. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download anarchitecture/combinatorics
More information about anarchitecture/combinatorics
Files in anarchitecture/combinatorics
Package combinatorics
Short Description Combinatorics helpers for functional pipelines (powerset, permutations, allocations) for PHP 8.5+.
License MIT
Informations about the package combinatorics
anarchitecture/combinatorics
Combinatorics helpers for functional pipelines in PHP 8.5+, designed to pair nicely with the pipe operator (|>) and the anarchitecture/pipe library.
This package intentionally focuses on search-space helpers (often exponential). Keep your core FP primitives in a smaller library, and pull these in when you need them.
Install
Usage
Functions
iterable_combinations(int $n)
Yield all subsets of exactly size $n from an iterable. Output is lazy; input is materialized into an array first.
- Preserves the original keys in each subset.
- Yields
C(count(items), n)combinations (binomial coefficient). - For
$n = 0, yields the empty subset only:[[]]. - Throws
InvalidArgumentExceptionif$n < 0.
iterable_powerset()
Yield all subsets (the power set) of an iterable. Output is lazy; input is materialized into an array first.
- Yields 2^n subsets, including the empty subset
[]. - Preserves the original keys in each subset.
iterable_permutations()
Yield all permutations of an iterable (materialized into an array). Output is lazy.
- Yields n! permutations.
- Preserves keys (keys stay attached to values; order changes).
iterable_allocations(int $total)
Given a list of items (keys), yield all allocations of a non-negative integer total across those keys.
- Each yielded allocation is an array keyed by the input keys, with non-negative integer values summing to
$total. - Yields
C(total + n - 1, n - 1)allocations (n = number of items).
Generate all non-negative integer allocations that sum to a fixed total.
License
MIT