Home / File/ cartesian.ts — tailwindcss Source File

cartesian.ts — tailwindcss Source File

Architecture documentation for cartesian.ts, a typescript file in the tailwindcss codebase. 0 imports, 1 dependents.

File typescript OxideEngine PreProcessors 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  698bd8b8_c58b_b939_11de_f35841f0236e["cartesian.ts"]
  978ac7fd_340e_c735_63b8_28b3651a84e1["canonicalize-candidates.test.ts"]
  978ac7fd_340e_c735_63b8_28b3651a84e1 --> 698bd8b8_c58b_b939_11de_f35841f0236e
  style 698bd8b8_c58b_b939_11de_f35841f0236e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

type CartesianInput = readonly unknown[][]

type CartesianResult<T extends CartesianInput> = T extends [
  infer Head extends unknown[],
  ...infer Tail extends CartesianInput,
]
  ? [Head[number], ...CartesianResult<Tail>]
  : []

export function* cartesian<T extends CartesianInput>(...sets: T): Generator<CartesianResult<T>> {
  let n = sets.length
  if (n === 0) return

  // If any input set is empty, the Cartesian product is empty.
  if (sets.some((set) => set.length === 0)) {
    return
  }

  // Index lookup
  let idx = Array(n).fill(0)

  while (true) {
    // Compute current combination
    let result = [] as CartesianResult<T>
    for (let i = 0; i < n; i++) {
      result[i] = sets[i][idx[i]]
    }
    yield result

    // Update index vector
    let k = n - 1
    while (k >= 0) {
      idx[k]++
      if (idx[k] < sets[k].length) {
        break
      }
      idx[k] = 0
      k--
    }

    if (k < 0) {
      return
    }
  }
}

Domain

Subdomains

Functions

Frequently Asked Questions

What does cartesian.ts do?
cartesian.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the OxideEngine domain, PreProcessors subdomain.
What functions are defined in cartesian.ts?
cartesian.ts defines 1 function(s): cartesian.
What files import cartesian.ts?
cartesian.ts is imported by 1 file(s): canonicalize-candidates.test.ts.
Where is cartesian.ts in the architecture?
cartesian.ts is located at packages/tailwindcss/src/cartesian.ts (domain: OxideEngine, subdomain: PreProcessors, directory: packages/tailwindcss/src).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free