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
  e4c0c36c_f52e_19ab_12c5_12a2ba42c88d["cartesian()"]
  4d385060_88c8_95d1_bd14_4eb53b36b689["cartesian.ts"]
  e4c0c36c_f52e_19ab_12c5_12a2ba42c88d -->|defined in| 4d385060_88c8_95d1_bd14_4eb53b36b689
  style e4c0c36c_f52e_19ab_12c5_12a2ba42c88d 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