Skip to content

feat(builtin): add ReadOnlyArray::rev_iter#3607

Merged
bobzhang merged 1 commit into
mainfrom
feat/readonlyarray-rev-iter
May 17, 2026
Merged

feat(builtin): add ReadOnlyArray::rev_iter#3607
bobzhang merged 1 commit into
mainfrom
feat/readonlyarray-rev-iter

Conversation

@bobzhang
Copy link
Copy Markdown
Contributor

Summary

  • Array, ArrayView, MutArrayView, and FixedArray (via its iter chain) all expose rev_iter to walk from the last element to the first. ReadOnlyArray had iter and iter2 but not the reverse counterpart.
  • Add it, delegating through ArrayView::rev_iter via self[:].

Test plan

  • moon check clean
  • moon fmt clean
  • moon test -p moonbitlang/core/builtin — 2833 tests pass (covers non-empty + empty cases)

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings May 17, 2026 09:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds reverse iteration support to ReadOnlyArray to match existing APIs on Array, ArrayView, MutArrayView, and FixedArray-based iter chains.

Changes:

  • Introduce ReadOnlyArray::rev_iter() implemented via self[:].rev_iter().
  • Add regression tests covering both non-empty and empty ReadOnlyArray reverse iteration.
  • Update generated builtin package interface (pkg.generated.mbti) to export the new method.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
builtin/readonlyarray.mbt Adds ReadOnlyArray::rev_iter() with documentation/example.
builtin/readonlyarray_test.mbt Extends iterator/sub-slicing test to cover rev_iter() on non-empty and empty arrays.
builtin/pkg.generated.mbti Exposes the new ReadOnlyArray::rev_iter signature in the generated interface.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread builtin/readonlyarray.mbt
/// arr.rev_iter().each(x => result.push(x))
/// debug_inspect(result, content="[3, 2, 1]")
/// }
/// ```
@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented May 17, 2026

Coverage Report for CI Build 4419

Coverage increased (+0.001%) to 94.193%

Details

  • Coverage increased (+0.001%) from the base build.
  • Patch coverage: 1 of 1 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 15877
Covered Lines: 14955
Line Coverage: 94.19%
Coverage Strength: 216306.31 hits per line

💛 - Coveralls

@bobzhang bobzhang force-pushed the feat/readonlyarray-rev-iter branch 5 times, most recently from 883538b to fe65432 Compare May 17, 2026 10:14
Array, ArrayView, MutArrayView, and FixedArray.iter() chain (via
Iter::rev — note Iter does not have rev) — all expose `rev_iter`,
which produces an iterator from last element to first. ReadOnlyArray
already had `iter` and `iter2` but not the reverse counterpart.

Implementation delegates to ArrayView::rev_iter via `self[:]`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@bobzhang bobzhang force-pushed the feat/readonlyarray-rev-iter branch from fe65432 to 51a0d5a Compare May 17, 2026 10:23
@bobzhang bobzhang merged commit 6eff663 into main May 17, 2026
14 checks passed
@bobzhang bobzhang deleted the feat/readonlyarray-rev-iter branch May 17, 2026 10:31
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.

3 participants