Skip to content

feat(array): add cartesianProduct and combinations#1713

Merged
raon0211 merged 3 commits into
mainfrom
claude/wonderful-golick-9187ca
May 8, 2026
Merged

feat(array): add cartesianProduct and combinations#1713
raon0211 merged 3 commits into
mainfrom
claude/wonderful-golick-9187ca

Conversation

@raon0211
Copy link
Copy Markdown
Collaborator

@raon0211 raon0211 commented May 8, 2026

Summary

Closes #1665, #1061

Adds two array utilities for enumerating tuples:

  • product(...arrs) — Cartesian product of input arrays, in lexicographic order with the rightmost array advancing fastest. Returns [[]] with no args; returns [] if any input is empty. Overloads (1–4 arrays) preserve tuple element types.
  • combinations(arr, r) — all r-length combinations from arr, in lexicographic order by position. Throws on negative or non-integer r. Returns [[]] when r === 0, [] when r > arr.length.

Interface follows Python's itertools.product and itertools.combinations. Algorithm for combinations is the standard index-odometer approach from the Python reference implementation. product allocates the result up front and fills each tuple with positional modulo arithmetic, avoiding intermediate prefix arrays.

Docs added in all four languages (en/ko/ja/zh_hans).

Test plan

  • yarn vitest run src/array/product src/array/combinations — 16 tests passing locally
  • yarn tsc --noEmit — clean
  • yarn eslint src/array/product.ts src/array/product.spec.ts src/array/combinations.ts src/array/combinations.spec.ts src/array/index.ts — clean

🤖 Generated with Claude Code

Adds two array utilities for enumerating tuples:
- `product(...arrs)` returns the Cartesian product in lexicographic order.
- `combinations(arr, r)` returns all r-length combinations.

Interface follows Python's `itertools.product` and `itertools.combinations`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@raon0211 raon0211 requested a review from dayongkr as a code owner May 8, 2026 07:53
@vercel
Copy link
Copy Markdown

vercel Bot commented May 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
es-toolkit Error Error May 8, 2026 8:15am

Request Review

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.85%. Comparing base (ddbe287) to head (e4b43dd).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1713   +/-   ##
=======================================
  Coverage   99.85%   99.85%           
=======================================
  Files         500      502    +2     
  Lines        4685     4730   +45     
  Branches     1361     1368    +7     
=======================================
+ Hits         4678     4723   +45     
  Misses          7        7           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Replace the "lexicographic order / odometer" shorthand with a step-by-step
description of how the rightmost array advances first and resets when its
left neighbor advances.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Disambiguate from arithmetic product. The math term "Cartesian product"
makes the intent obvious at the call site.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@raon0211 raon0211 changed the title feat(array): add product and combinations feat(array): add cartesianProduct and combinations May 8, 2026
@raon0211 raon0211 merged commit 0813a3f into main May 8, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: combinations

2 participants