Skip to content

feat(collections/unstable): add index arg to methods#6382

Merged
kt3k merged 5 commits intodenoland:mainfrom
canac:collections-index-arg
Jan 13, 2026
Merged

feat(collections/unstable): add index arg to methods#6382
kt3k merged 5 commits intodenoland:mainfrom
canac:collections-index-arg

Conversation

@canac
Copy link
Copy Markdown
Contributor

@canac canac commented Feb 5, 2025

Adds an index arg to collections' predicate/selector/transformer/discriminator method. I added it only to collection helpers that operate on iterables because collection helpers that operate on records don't seem as likely to need access to the key index. Please let me know if I missed any.

Closes #6288

@canac canac requested a review from kt3k as a code owner February 5, 2025 02:14
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 5, 2025

Codecov Report

❌ Patch coverage is 66.08187% with 116 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.07%. Comparing base (6b93b78) to head (d2d5bb9).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
collections/unstable_min_of.ts 30.55% 25 Missing ⚠️
collections/unstable_max_of.ts 36.11% 22 Missing and 1 partial ⚠️
collections/unstable_max_by.ts 50.00% 18 Missing ⚠️
collections/unstable_min_by.ts 50.00% 18 Missing ⚠️
collections/unstable_drop_while.ts 33.33% 14 Missing ⚠️
collections/unstable_take_last_while.ts 47.61% 11 Missing ⚠️
collections/unstable_sort_by.ts 85.18% 3 Missing and 1 partial ⚠️
collections/unstable_first_not_nullish_of.ts 83.33% 2 Missing ⚠️
collections/unstable_drop_last_while.ts 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6382      +/-   ##
==========================================
- Coverage   94.28%   94.07%   -0.22%     
==========================================
  Files         584      600      +16     
  Lines       43186    43528     +342     
  Branches     6933     6986      +53     
==========================================
+ Hits        40720    40947     +227     
- Misses       2413     2526     +113     
- Partials       53       55       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

@kt3k kt3k added suggestion a suggestion yet to be agreed feedback welcome We want community's feedback on this issue or PR labels Feb 5, 2025
@kt3k
Copy link
Copy Markdown
Contributor

kt3k commented Feb 5, 2025

I'm generally in favor of the idea. It looks useful in several places, and also this is aligned to the design of builtin map methods (such as map, filter, forEach, etc)

What do people think?


Note: Currently we have policy of accepting any new feature in unstable_ prefixed path. That requires all these APIs duplicated in unstable_foo.ts, but that feels too unwieldy in this case. I'll discuss with core team about how to handle this particular case.

@timreichen
Copy link
Copy Markdown
Contributor

What do people think?

I like it.

@kt3k kt3k added the feat-stable feature addition to the stable API label May 4, 2025
@iuioiua
Copy link
Copy Markdown
Contributor

iuioiua commented Aug 18, 2025

I'm in favour.

@iuioiua
Copy link
Copy Markdown
Contributor

iuioiua commented Sep 9, 2025

@kt3k should we add this in?

@canac
Copy link
Copy Markdown
Contributor Author

canac commented Sep 9, 2025

I'm more than happy to rebase this if we want to move forward with it. Just let me know!

@iuioiua
Copy link
Copy Markdown
Contributor

iuioiua commented Sep 9, 2025

I suggest rebasing anyway 🙂

@canac canac force-pushed the collections-index-arg branch from bff3bbf to c0c394e Compare September 10, 2025 14:18
@iuioiua
Copy link
Copy Markdown
Contributor

iuioiua commented Nov 19, 2025

@kt3k, it seems like this is a good idea to add.

@tomas-zijdemans
Copy link
Copy Markdown
Contributor

I support adding this!

@canac canac force-pushed the collections-index-arg branch from c0c394e to b6b83da Compare January 10, 2026 14:01
Copy link
Copy Markdown
Contributor

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, sorry for the very long delay in response!

This looks good to me. Let's first try these behaviors as unstable features. (I moved all implementations to unstable version of each API)

@kt3k kt3k changed the title feat(collections): add index arg to methods feat(collections/unstable): add index arg to methods Jan 13, 2026
@kt3k kt3k merged commit c3e47e8 into denoland:main Jan 13, 2026
20 checks passed
@kt3k
Copy link
Copy Markdown
Contributor

kt3k commented Jan 13, 2026

(Unrelated side note: I initially thought it might be better to change our new feature policy (all feature should be unstable first) to land this PR directly, but somehow failed to invent a new policy. That delayed the review process/decision...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

collections feat-stable feature addition to the stable API feedback welcome We want community's feedback on this issue or PR suggestion a suggestion yet to be agreed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[collections] Pass index to partition callback

5 participants