Home / Function/ combinations() — tailwindcss Function Reference

combinations() — tailwindcss Function Reference

Architecture documentation for the combinations() function in canonicalize-candidates.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  d195fa22_71c2_5bb5_0db2_368d87eec97e["combinations()"]
  830bd29f_3420_9239_4bdf_20fd57106bdf["collapseCandidates()"]
  830bd29f_3420_9239_4bdf_20fd57106bdf -->|calls| d195fa22_71c2_5bb5_0db2_368d87eec97e
  style d195fa22_71c2_5bb5_0db2_368d87eec97e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/tailwindcss/src/canonicalize-candidates.ts lines 2574–2600

function* combinations<T>(arr: T[]): Generator<T[]> {
  let n = arr.length
  let limit = 1n << BigInt(n)

  for (let k = n; k >= 2; k--) {
    let mask = (1n << BigInt(k)) - 1n

    while (mask < limit) {
      let out = []
      for (let i = 0; i < n; i++) {
        if ((mask >> BigInt(i)) & 1n) {
          out.push(arr[i])
        }
      }
      yield out

      // Gosper's hack:
      // - https://programmingforinsomniacs.blogspot.com/2018/03/gospers-hack-explained.html
      // - https://rosettacode.org/wiki/Gosper%27s_hack
      //
      // We need to generate the next mask in lexicographical order.
      let carry = mask & -mask
      let ripple = mask + carry
      mask = (((ripple ^ mask) >> 2n) / carry) | ripple
    }
  }
}

Domain

Subdomains

Frequently Asked Questions

What does combinations() do?
combinations() is a function in the tailwindcss codebase.
What calls combinations()?
combinations() is called by 1 function(s): collapseCandidates.

Analyze Your Own Codebase

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

Try Supermodel Free