Skip to content

feat(data-structures/unstable): align RollingCounter with other data structures, add at() and toArray()#7102

Open
tomas-zijdemans wants to merge 3 commits intodenoland:mainfrom
tomas-zijdemans:rolling-next
Open

feat(data-structures/unstable): align RollingCounter with other data structures, add at() and toArray()#7102
tomas-zijdemans wants to merge 3 commits intodenoland:mainfrom
tomas-zijdemans:rolling-next

Conversation

@tomas-zijdemans
Copy link
Copy Markdown
Contributor

This PR is mostly about aligning RollingCounter with Deque, IndexedHeap, MultiMap and other data-structures.

  • RollingCounter now implements Iterable.
  • [Symbol.toStringTag] is a readonly "RollingCounter" as const property (was a getter).
  • @experimental tag added to every public-member JSDoc.
  • Class JSDoc gained a complexity table.
  • New at(index) with Array.prototype.at semantics (oldest→newest, negatives from newest end, out-of-range → undefined).
  • New toArray(); toJSON() delegates to it.
  • RollingCounterSnapshot.segments is readonly number[]; field is readonly.
  • from() accepts RollingCounterSnapshot, guards null/undefined/non-object, throws TypeError for shape errors, keeps RangeError for per-element numeric errors.
  • Tests: two RangeError cases flipped to TypeError; added null/undefined snapshot, toArray, and at tests.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

❌ Patch coverage is 96.96970% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 94.61%. Comparing base (a496da2) to head (46f73eb).

Files with missing lines Patch % Lines
data_structures/unstable_rolling_counter.ts 96.96% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7102      +/-   ##
==========================================
- Coverage   94.61%   94.61%   -0.01%     
==========================================
  Files         634      634              
  Lines       51801    51818      +17     
  Branches     9329     9336       +7     
==========================================
+ Hits        49011    49027      +16     
  Misses       2216     2216              
- Partials      574      575       +1     

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

Copy link
Copy Markdown
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

Overall solid PR. The new at() and toArray() methods are well-implemented, and the alignment changes (Iterable, readonly snapshot, @experimental tags, complexity table, Symbol.toStringTag as property) are all consistent with how Deque and other data structures work in this repo. Tests are thorough.

Two things:

1. Empty segments should throw RangeError, not TypeError

An empty array is the correct type — it's just the wrong length. The constructor throws RangeError for the equivalent constraint (segmentCount < 1), so from() should do the same for consistency. The other two TypeError changes (null/non-object snapshot, non-array segments) are correct.

2. PR scope vs title

The title says "add at() and toArray()" but the PR also changes the snapshot interface to readonly, adds implements Iterable<number>, switches Symbol.toStringTag to a readonly property, adds @experimental to all members, adds the complexity table, and reworks from() validation. The description documents all of this, but the commit message will be misleading in git log. Worth updating the title/commit message to something broader like "align RollingCounter with other data structures, add at() and toArray()".

@tomas-zijdemans tomas-zijdemans changed the title feat(data-structures/unstable): add RollingCounter.at() and toArray() feat(data-structures/unstable): align RollingCounter with other data structures, add at() and toArray() Apr 28, 2026
…structures, add `at()` and `toArray()`

Made-with: Cursor
@tomas-zijdemans
Copy link
Copy Markdown
Contributor Author

Thanks,

  • PR title and commit message changed as requested
  • Changed from TypeError to RangeError as requested

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants