Home / Function/ cartesian() — tailwindcss Function Reference

cartesian() — tailwindcss Function Reference

Architecture documentation for the cartesian() function in cartesian.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  be3438c9_e99f_79d9_040f_6198e91ce8dd["cartesian()"]
  698bd8b8_c58b_b939_11de_f35841f0236e["cartesian.ts"]
  be3438c9_e99f_79d9_040f_6198e91ce8dd -->|defined in| 698bd8b8_c58b_b939_11de_f35841f0236e
  style be3438c9_e99f_79d9_040f_6198e91ce8dd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/tailwindcss/src/cartesian.ts lines 10–45

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

Frequently Asked Questions

What does cartesian() do?
cartesian() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/cartesian.ts.
Where is cartesian() defined?
cartesian() is defined in packages/tailwindcss/src/cartesian.ts at line 10.

Analyze Your Own Codebase

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

Try Supermodel Free