Created
June 10, 2022 11:28
-
-
Save composite/06db4d604d5d6110624f77427c0eb6d5 to your computer and use it in GitHub Desktop.
The useful Typescript utilities
This file contains hidden or 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
| /** | |
| * Array Cartesian Product | |
| */ | |
| const cartesian = <T,>(...arr: (T extends unknown[] ? never : T)[][]) => | |
| arr.reduce((a, b) => a.flatMap((x) => b.map((y) => [...x, y])), [ | |
| [] as T[], | |
| ] as T[][]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment