Skip to content

feat(Array): add dropLast and dropRight functions#724

Open
XiayiZhang wants to merge 3 commits into
neohaskell:mainfrom
XiayiZhang:feature/dropLast
Open

feat(Array): add dropLast and dropRight functions#724
XiayiZhang wants to merge 3 commits into
neohaskell:mainfrom
XiayiZhang:feature/dropLast

Conversation

@XiayiZhang

@XiayiZhang XiayiZhang commented Jul 12, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • New Features

    • Added dropLast to remove the final element from an array.
    • Added dropRight to remove the last n elements from an array.
    • Clear handling for empty arrays and non-positive or out-of-range n.
  • Tests

    • Added a new test suite covering dropLast and dropRight, including edge cases.

- dropLast removes last element, returns empty if empty
- dropRight removes N elements from end, clamps safely
- Export both functions in module header

Closes neohaskell#704
@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6d50ad4d-47fd-406e-9bcf-84c7aac5e3c6

📥 Commits

Reviewing files that changed from the base of the PR and between 844c992 and 5d12804.

📒 Files selected for processing (1)
  • core/core/Array.hs

Walkthrough

The Array API adds dropLast and dropRight, implemented with existing primitives and tested across normal and boundary cases.

Changes

Array drop operations

Layer / File(s) Summary
Drop operations and validation
core/core/Array.hs, core/test/ArraySpec.hs
dropLast and dropRight are exported and implement defined boundary behavior; tests cover non-empty, empty, zero-count, and length-boundary cases.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • Issue 704 — Directly tracks the addition of Array.dropLast and Array.dropRight, including edge-case behavior and tests.

Suggested reviewers: nickseagull

Poem

By decree, the final elements part,
One drops the last, one counts the chart.
Empty arrays remain serene,
Zero drops leave what has been.
Tests stand guard in orderly flight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding dropLast and dropRight to Array.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@NickSeagull NickSeagull left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey, thanks for the PR!

Can you ensure the doc comments are in english, and also include an extension of the Array test suite for this change? Thanks!

Comment thread core/core/Array.hs Outdated
Comment on lines +586 to +589
dropLast :: Array a -> Array a
dropLast arr@(Array vector)
| Data.Vector.null vector = arr
| otherwise = Array (Data.Vector.init vector)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you use the existing functions in this module rather than wrapping unwrapping?

Also, do not use guards, we use if..then..else

Comment thread core/core/Array.hs Outdated
Comment on lines +602 to +607
dropRight n arr =
let len = length arr
keep = max 0 (len - n)
in if keep == len
then arr
else Array (Data.Vector.take keep (unwrap arr))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

use do...let instead of let..in. Also, use the other functions when possible

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

oops, sry 😅 i'll fix it up. sorry to bother you

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not bothering at all! thanks!

@XiayiZhang

Copy link
Copy Markdown
Author

i've optimized the code and added tests based on the reviewer's feedback. pls review again😸️

@NickSeagull
NickSeagull marked this pull request as ready for review July 15, 2026 16:44

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/core/Array.hs`:
- Line 587: Replace the single-letter type variable a with a descriptive
multi-letter variable such as element in the dropLast signature at
core/core/Array.hs lines 587-587 and the dropRight signature at
core/core/Array.hs lines 604-604, updating each corresponding type declaration
consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: d552b189-7d4e-4573-baa1-31c2c46d489e

📥 Commits

Reviewing files that changed from the base of the PR and between a2c76f4 and 844c992.

📒 Files selected for processing (2)
  • core/core/Array.hs
  • core/test/ArraySpec.hs

Comment thread core/core/Array.hs Outdated
@NickSeagull

Copy link
Copy Markdown
Member

@XiayiZhang thanks a lot for the changes!

One last request, can you run ./dev codemap and commit the result?

It comes from GitHub Actions, it is a step that we use to generate contextual information for the agents to work more efficiently.

@NickSeagull NickSeagull left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks great now! Can you run ./dev codemap and push the changes so that CICD can run? I will merge afterwards.

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.

2 participants