Skip to content
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

add Iter::map_option #1151

Merged
merged 2 commits into from
Oct 23, 2024
Merged

add Iter::map_option #1151

merged 2 commits into from
Oct 23, 2024

Conversation

Yoorkin
Copy link
Collaborator

@Yoorkin Yoorkin commented Oct 21, 2024

Iter::map_option serves the same functionality as Array::map_option.

Copy link

peter-jerry-ye-code-review bot commented Oct 21, 2024

From the provided git diff output, here are three potential issues or areas of improvement in the MoonBit code:

  1. Unused Function Parameter in map_option:
    In the map_option function, there is a parameter A that is used in the type signature but not directly used within the function body. This might be intentional if A is used indirectly through the closure f, but it could also be a potential oversight if A was meant to be used elsewhere.

    pub fn map_option[A, B](self : Iter[A], f : (A) -> B?) -> Iter[B] {
      fn(yield) {
        self.run(
          fn(a) {
            match f(a) {
              Some(b) => yield(b)
              None => IterContinue
            }
          },
        )
      }
    }
    
  2. Lack of Error Handling in map_option:
    The map_option function uses IterContinue to handle the case where the mapping function returns None. This is a valid approach in this context, but it might be worth adding a comment to explain why IterContinue is used instead of another approach, especially since MoonBit supports error handling constructs like raise.

    match f(a) {
      Some(b) => yield(b)
      None => IterContinue // Consider adding a comment explaining why IterContinue is used
    }
    
  3. Inconsistent Naming Convention in Tests:
    The test function names in iter_test.mbt are inconsistent. For example, map is named directly after the function being tested, while map_option is named with additional context (map_option). It might be beneficial to standardize the naming convention for better readability and consistency.

    test "map" {
      ...
    }
    
    test "map_option" { // Consider renaming to "map_option" or adding more context
      ...
    }
    

These suggestions aim to improve clarity, consistency, and potential robustness of the code.

@Yoorkin Yoorkin requested a review from bobzhang October 21, 2024 03:57
@coveralls
Copy link
Collaborator

coveralls commented Oct 21, 2024

Pull Request Test Coverage Report for Build 3670

Details

  • 5 of 5 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 82.761%

Totals Coverage Status
Change from base Build 3667: 0.02%
Covered Lines: 4263
Relevant Lines: 5151

💛 - Coveralls

@bobzhang bobzhang merged commit 37ca3e9 into main Oct 23, 2024
13 checks passed
@bobzhang bobzhang deleted the iter-map-option branch October 23, 2024 00:55
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