Skip to content

Add for comprehension support to UsingUtils with resource management and guards, and extend test coverage.#819

Merged
yruslan merged 1 commit intomasterfrom
feature/add-for-comprehensions-for-using-semantics
Feb 6, 2026
Merged

Add for comprehension support to UsingUtils with resource management and guards, and extend test coverage.#819
yruslan merged 1 commit intomasterfrom
feature/add-for-comprehensions-for-using-semantics

Conversation

@yruslan
Copy link
Collaborator

@yruslan yruslan commented Feb 6, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for Scala for-comprehension syntax when managing AutoCloseable resources
    • Enabled filtering and chaining patterns in resource management workflows
  • Tests

    • Expanded test coverage for resource management scenarios, including nested resources, error handling, and predicate-based filtering

…ent and guards, and extend test coverage.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 6, 2026

Walkthrough

Adds implicits-based resource management utilities enabling for-comprehension syntax with AutoCloseable resources. Introduces ResourceWrapper and FilteredResourceWrapper classes supporting foreach, map, flatMap, and withFilter operations for resource chaining and predicate-based filtering. Includes comprehensive test coverage for various workflows and error scenarios.

Changes

Cohort / File(s) Summary
Core Utilities
cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/utils/UsingUtils.scala
Adds Implicits object with implicit ResourceWrapper[T <: AutoCloseable] class providing foreach, map, flatMap, and withFilter methods. Introduces FilteredResourceWrapper[T <: AutoCloseable] class supporting predicate-based filtering with chainable withFilter and resource lifecycle methods.
Test Coverage
cobol-parser/src/test/scala/za/co/absa/cobrix/cobol/utils/UsingUtilsSuite.scala
Expands test suite to cover single/multi-resource workflows, for-comprehension guards with filters, error handling during action/close/creation phases, exception suppression behavior, and nested generator scenarios.

Sequence Diagram

sequenceDiagram
    participant Client
    participant ResourceWrapper
    participant FilteredResourceWrapper
    participant Resource as AutoCloseable<br/>Resource
    participant Using as using()
    
    Client->>ResourceWrapper: for (r <- resource)
    ResourceWrapper->>Using: creates using(resource)
    Using->>Resource: acquire
    Resource-->>Using: resource ready
    
    alt with withFilter
        Client->>FilteredResourceWrapper: withFilter(predicate)
        FilteredResourceWrapper->>FilteredResourceWrapper: store predicate
        FilteredResourceWrapper->>FilteredResourceWrapper: foreach/map/flatMap
        alt predicate is true
            FilteredResourceWrapper->>Resource: apply operation
            Resource-->>FilteredResourceWrapper: result
        else predicate is false
            FilteredResourceWrapper->>FilteredResourceWrapper: skip operation
        end
    else direct operation
        ResourceWrapper->>Resource: apply foreach/map/flatMap
        Resource-->>ResourceWrapper: result
    end
    
    ResourceWrapper->>Using: cleanup
    Using->>Resource: close
    Resource-->>Using: closed
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through Scala's fold,
With implicits swift and comprehensions bold,
Resources wrapped in for-loops divine,
FilteredWrappers filter just fine,
AutoCloseable friends now safely align! 🔐

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding for-comprehension support to UsingUtils with resource management and guard functionality, plus extended test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/add-for-comprehensions-for-using-semantics

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 and usage tips.

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

JaCoCo code coverage report - 'cobol-parser'

Overall Project 91.64% -0.03% 🍏
Files changed 82.61% 🍏

File Coverage
UsingUtils.scala 87.32% -11.27% 🍏

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

JaCoCo code coverage report - 'spark-cobol'

Overall Project 81.96% 🍏

There is no coverage information present for the Files changed

@yruslan yruslan merged commit 7776875 into master Feb 6, 2026
13 checks passed
@yruslan yruslan deleted the feature/add-for-comprehensions-for-using-semantics branch February 6, 2026 11:05
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.

1 participant