8000 docs: fixed unidiomatic example by HCHogan · Pull Request #2416 · moonbitlang/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

docs: fixed unidiomatic example #2416

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
Jul 7, 2025
Merged

docs: fixed unidiomatic example #2416

merged 1 commit into from
Jul 7, 2025

Conversation

HCHogan
Copy link
Contributor
@HCHogan HCHogan commented Jul 7, 2025

No description provided.

Copy link
Inconsistent lambda syntax in documentation examples

Category
Maintainability
Code Snippet
// deque/deque.mbt lines around 1452-1461
let find_3 = dq.binary_search_by((x) => {
x.compare(3)
})
// vs
let find_4 = dq.binary_search_by((x) => {
x.compare(4)
})
Recommendation
Use consistent lambda parameter syntax across all examples. Either use (x) => or x => consistently.
Reasoning
The deque examples show inconsistent lambda syntax - some use (x) => while the original code used x =>. This inconsistency in documentation can confuse readers about the proper syntax.

Excellent simplification of comparison logic

Category
Maintainability
Code Snippet
// Before:
if x < 3 {
-1
} else if x > 3 {
1
} else {
0
}

// After:
x.compare(3)
Recommendation
Continue this pattern across the codebase for any similar verbose comparison examples.
Reasoning
The change from verbose if-else chains to using the built-in compare method significantly improves readability and demonstrates best practices. This is exactly how comparison should be done in MoonBit.

Documentation examples are functionally equivalent and correct

Category
Correctness
Code Snippet
x.compare(3) // Returns -1, 0, or 1 based on comparison
Recommendation
No changes needed - the refactored examples maintain the same behavior while being more concise.
Reasoning
The compare method correctly returns the same values (-1, 0, 1) as the original if-else logic, ensuring the documentation examples remain accurate and functional.

@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 238

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 220: 0.0%
Covered Lines: 3464
Relevant Lines: 3884

💛 - Coveralls

@bobzhang bobzhang merged commit 4c7eae1 into moonbitlang:main Jul 7, 2025
10 of 14 checks passed
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