vavr icon indicating copy to clipboard operation
vavr copied to clipboard

Add support for threaded use of Try.withResources() for up to 3 arguments

Open thinstripe opened this issue 2 years ago • 1 comments

It would be useful to be able to thread your Autocloseable resources when using Try.withResources() in common scenarios/use cases such as database related resource management (Connection, PreparedStatement, ResultSet).

For example :-

Try.withResources(dataSource::getConnection, conn -> conn.prepareStatement("SELECT id, name from books"), PreparedStatement::executeQuery).of(rs -> /* extract what you need from ResultSet */)

Is equivalent but preferable to :-

Try.of(() -> try(Connection conn = dataSource.getConnection(); PreparedStatement stmt = conn.prepareStatement("SELECT id, name from books"); ResultSet rs = stmt.executeQuery())).flatMap(rs -> /* extract what you need from ResultSet */);

thinstripe avatar Nov 24 '23 17:11 thinstripe

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Please upload report for BASE (version/1.x@58698b7). Learn more about missing BASE report.

Additional details and impacted files
@@              Coverage Diff               @@
##             version/1.x    #2752   +/-   ##
==============================================
  Coverage               ?   92.85%           
  Complexity             ?     5273           
==============================================
  Files                  ?       89           
  Lines                  ?    12574           
  Branches               ?     1598           
==============================================
  Hits                   ?    11675           
  Misses                 ?      711           
  Partials               ?      188           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Mar 08 '25 13:03 codecov[bot]