8000 feat: update list functions to handle error polymorphism by FlyCloudC · Pull Request #2353 · moonbitlang/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

feat: update list functions to handle error polymorphism #2353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025

Conversation

FlyCloudC
Copy link
Contributor

No description provided.

Copy link
peter-jerry-ye-code-review bot commented Jun 26, 2025
Documentation doesn't reflect error handling capabilities

Category
Maintainability
Code Snippet
/// assert_eq(@list.of([1, 2, 3, 4, 5]).map(fn(x){ x * 2}), @list.of([2, 4, 6, 8, 10]))
pub fn[A, B] map(self : T[A], f : (A) -> B raise?) -> T[B] raise?
Recommendation
Update documentation to include error handling examples and mention that the mapping function can raise errors. Example:

/// Maps elements using f, which may raise errors
/// ```mbt
///   // Success case
///   assert_eq(@list.of([1, 2]).map(fn(x){ x * 2}), @list.of([2, 4]))
///   // Error case
///   @list.of([1]).map(fn(x) { raise "error" }) // raises error
/// ```
**Reasoning**
The current documentation only shows successful cases. Since error handling is now part of the API contract, users should understand when and how errors can occur.

</details>
<details>

<summary> Inconsistent error handling in fold operations </summary>

**Category**
Correctness
**Code Snippet**
pub fn[A, B] rev_fold(self : T[A], init~ : B, (B, A) -> B) -> B
pub fn[A, B] fold(self : T[A], init~ : B, f : (B, A) -> B raise?) -> B raise?
**Recommendation**
Add raise? annotations to rev_fold for consistency:
```moonbit
pub fn[A, B] rev_fold(self : T[A], init~ : B, f : (B, A) -> B raise?) -> B raise?
**Reasoning**
fold and rev_fold are complementary operations but have different error handling capabilities. This inconsistency could lead to unexpected behavior when refactoring code.

</details>
<details>

<summary> Potentially redundant error propagation in nested operations </summary>

**Category**
Maintainability
**Code Snippet**
pub fn[A, B] scan_right(self : T[A], f : (B, A) -> B raise?, init~ : B) -> T[B] raise? {
  self.rev().scan_left(f, init~).reverse_inplace()
}
**Recommendation**
Consider consolidating error handling for composite operations:
```moonbit
pub fn[A, B] scan_right(self : T[A], f : (B, A) -> B raise?, init~ : B) -> T[B] raise? {
  try {
    let reversed = self.rev()
    let scanned = reversed.scan_left(f, init~)
    scanned.reverse_inplace()
  }
}
**Reasoning**
The current implementation chains operations that can raise errors. Making the error flow more explicit would help with debugging and make the code's intent clearer.

</details>

@coveralls
Copy link
Collaborator
coveralls commented Jun 26, 2025

Pull Request Test Coverage Report for Build 45

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 89.186%

Totals Coverage Status
Change from base Build 44: 0.0%
Covered Lines: 3464
Relevant Lines: 3884

💛 - Coveralls

@peter-jerry-ye peter-jerry-ye enabled auto-merge (rebase) June 26, 2025 04:41
@peter-jerry-ye peter-jerry-ye merged commit 6e2498c into moonbitlang:main Jun 26, 2025
10 checks passed
@FlyCloudC FlyCloudC deleted the list-raise branch June 26, 2025 04:50
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
0