-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65ff783
commit 175307e
Showing
2 changed files
with
37 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Internal; | ||
|
||
use function array_shift; | ||
|
||
final class CombinationsHelper | ||
{ | ||
|
||
/** | ||
* @param array<mixed> $arrays | ||
* @return iterable<mixed> | ||
*/ | ||
public static function combinations(array $arrays): iterable | ||
{ | ||
// from https://stackoverflow.com/a/70800936/565782 by Arnaud Le Blanc | ||
if ($arrays === []) { | ||
yield []; | ||
return; | ||
} | ||
|
||
$head = array_shift($arrays); | ||
|
||
foreach ($head as $elem) { | ||
foreach (self::combinations($arrays) as $combination) { | ||
$comb = [$elem]; | ||
foreach ($combination as $c) { | ||
$comb[] = $c; | ||
} | ||
yield $comb; | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters