Skip to content

Instantly share code, notes, and snippets.

@composite
Created June 10, 2022 11:28
Show Gist options
  • Select an option

  • Save composite/06db4d604d5d6110624f77427c0eb6d5 to your computer and use it in GitHub Desktop.

Select an option

Save composite/06db4d604d5d6110624f77427c0eb6d5 to your computer and use it in GitHub Desktop.
The useful Typescript utilities
/**
* 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