Skip to content

feature: #95 | Implement Throwing Functional Lambdas#97

Merged
a-anand-91119 merged 1 commit intodevelopfrom
95-throwable-functional-lambdas
Nov 23, 2025
Merged

feature: #95 | Implement Throwing Functional Lambdas#97
a-anand-91119 merged 1 commit intodevelopfrom
95-throwable-functional-lambdas

Conversation

@ShivamNagpal
Copy link
Copy Markdown
Contributor

@ShivamNagpal ShivamNagpal commented Sep 26, 2025

This pull request introduces a suite of custom functional interfaces that mirror the standard Java functional interfaces, but allow their methods to throw checked exceptions. Additionally, comprehensive unit tests are provided for each new interface to ensure correct behavior and exception handling. These changes make it easier to use lambdas and method references that throw checked exceptions in functional programming contexts.

New functional interfaces supporting checked exceptions

  • Added ThrowingConsumer, ThrowingBiConsumer, ThrowingFunction, ThrowingBiFunction, ThrowingSupplier, and ThrowingRunnable interfaces in src/main/java/org/zeplinko/commons/lang/ext/util/function/, each allowing their main method to throw a checked Exception. [1] [2] [3] [4] [5] [6]

Unit tests for new interfaces

  • Added unit tests for each interface in src/test/java/org/zeplinko/commons/lang/ext/util/function/, verifying normal operation, null handling, exception propagation, repeated invocation, and handling of complex objects. [1] [2] [3] [4] [5] [6]

Summary by CodeRabbit

Release Notes

  • New Features

    • Added six new utility interfaces enabling exception-aware functional operations with support for checked exception handling.
  • Tests

    • Introduced comprehensive test coverage validating exception propagation, null handling, and operational consistency across all new utilities.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Sep 26, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

These changes introduce 6 new functional interfaces in the org.zeplinko.commons.lang.ext.util.function package that mirror standard Java functional interfaces (Consumer, Function, Supplier, BiConsumer, BiFunction, Runnable) but declare methods throwing checked Exception. Comprehensive test suites validate normal operation, null handling, exception propagation, and repeated invocations for each interface.

Changes

Cohort / File(s) Summary
Throwing Functional Interfaces
src/main/java/org/zeplinko/commons/lang/ext/util/function/Throwing{Consumer, Function, Supplier, BiConsumer, BiFunction, Runnable}.java
Six new @FunctionalInterface declarations mirroring standard Java functional interfaces but allowing checked exceptions. Each defines a single method (accept/apply/run/get) with throws Exception clause.
Throwing Functional Interface Tests
src/test/java/org/zeplinko/commons/lang/ext/util/function/Throwing{Consumer, Function, Supplier, BiConsumer, BiFunction, Runnable}Test.java
Six new JUnit test suites validating: basic invocation with values, null input/output handling, checked exception propagation with message and type verification, multiple successive invocations, and complex object handling.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

  • All functional interfaces follow a uniform, minimal pattern (single method declaration with throws Exception)
  • Test files exhibit consistent test structure and scenarios across all six test classes
  • No complex logic, control flow modifications, or intricate interactions
  • Changes are highly homogeneous and repetitive, reducing cognitive load per file

Poem

🐰 Six new friends in function's lair,
Each one throws with utmost care!
Consumer, Function, Supplier too,
Checked exceptions flowing through—
No more catching, just declare,
Rabbit's gift beyond compare! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feature: #95 | Implement Throwing Functional Lambdas' clearly and directly describes the main change: introducing functional interface implementations that support throwing checked exceptions.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 95-throwable-functional-lambdas

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 38087a1 and 0042a02.

📒 Files selected for processing (12)
  • src/main/java/org/zeplinko/commons/lang/ext/util/function/ThrowingBiConsumer.java (1 hunks)
  • src/main/java/org/zeplinko/commons/lang/ext/util/function/ThrowingBiFunction.java (1 hunks)
  • src/main/java/org/zeplinko/commons/lang/ext/util/function/ThrowingConsumer.java (1 hunks)
  • src/main/java/org/zeplinko/commons/lang/ext/util/function/ThrowingFunction.java (1 hunks)
  • src/main/java/org/zeplinko/commons/lang/ext/util/function/ThrowingRunnable.java (1 hunks)
  • src/main/java/org/zeplinko/commons/lang/ext/util/function/ThrowingSupplier.java (1 hunks)
  • src/test/java/org/zeplinko/commons/lang/ext/util/function/ThrowingBiConsumerTest.java (1 hunks)
  • src/test/java/org/zeplinko/commons/lang/ext/util/function/ThrowingBiFunctionTest.java (1 hunks)
  • src/test/java/org/zeplinko/commons/lang/ext/util/function/ThrowingConsumerTest.java (1 hunks)
  • src/test/java/org/zeplinko/commons/lang/ext/util/function/ThrowingFunctionTest.java (1 hunks)
  • src/test/java/org/zeplinko/commons/lang/ext/util/function/ThrowingRunnableTest.java (1 hunks)
  • src/test/java/org/zeplinko/commons/lang/ext/util/function/ThrowingSupplierTest.java (1 hunks)
🔇 Additional comments (12)
src/main/java/org/zeplinko/commons/lang/ext/util/function/ThrowingBiFunction.java (1)

1-31: LGTM! Clean and well-documented functional interface.

The ThrowingBiFunction interface is well-structured with comprehensive Javadoc and follows the standard functional interface pattern. The signature appropriately mirrors java.util.function.BiFunction while allowing checked exceptions.

src/main/java/org/zeplinko/commons/lang/ext/util/function/ThrowingFunction.java (1)

1-29: LGTM! Well-designed throwing variant of Function.

The interface follows the same clean pattern as ThrowingBiFunction with appropriate documentation and method signature.

src/test/java/org/zeplinko/commons/lang/ext/util/function/ThrowingRunnableTest.java (1)

1-55: LGTM! Comprehensive test coverage for ThrowingRunnable.

The test suite thoroughly validates all important scenarios including successful execution, multiple invocations, exception propagation, side effects, and no-op behavior. The test structure is clear and follows good testing practices.

src/test/java/org/zeplinko/commons/lang/ext/util/function/ThrowingSupplierTest.java (1)

1-51: LGTM! Thorough test coverage for ThrowingSupplier.

The test suite validates all key behaviors including value return, null handling, exception propagation, consistency across invocations, and complex object handling. The combination of assertSame and assertArrayEquals on lines 48-49 appropriately validates both reference identity and content equality.

src/main/java/org/zeplinko/commons/lang/ext/util/function/ThrowingBiConsumer.java (1)

1-29: LGTM! Consistent and well-documented BiConsumer variant.

The interface follows the established pattern with clear documentation and appropriate method signature mirroring java.util.function.BiConsumer.

src/main/java/org/zeplinko/commons/lang/ext/util/function/ThrowingSupplier.java (1)

1-26: LGTM! Clean implementation of throwing Supplier.

The interface is well-documented and maintains consistency with the other throwing functional interfaces in this PR.

src/main/java/org/zeplinko/commons/lang/ext/util/function/ThrowingConsumer.java (1)

1-27: LGTM! Well-structured Consumer variant.

The interface maintains consistency with the other throwing functional interfaces and provides clear documentation for its purpose.

src/main/java/org/zeplinko/commons/lang/ext/util/function/ThrowingRunnable.java (1)

1-24: LGTM! Consistent Runnable variant with proper documentation.

The interface follows the established pattern and the Javadoc formatting at lines 11-13 is consistent with the other throwing interfaces in this PR (one blank line before @author).

src/test/java/org/zeplinko/commons/lang/ext/util/function/ThrowingConsumerTest.java (1)

1-63: Excellent test coverage for ThrowingConsumer!

The test suite is comprehensive and well-structured, covering:

  • Normal operation with value consumption
  • Null value handling
  • Checked exception propagation with proper type validation
  • Multiple invocations to verify stateless behavior
  • Complex object handling with reference equality checks

The tests effectively validate the contract of the ThrowingConsumer interface.

src/test/java/org/zeplinko/commons/lang/ext/util/function/ThrowingFunctionTest.java (1)

1-59: Thorough test coverage for ThrowingFunction!

The test suite comprehensively validates the ThrowingFunction interface with:

  • Basic transformation operations using method references
  • Null input handling with conditional logic
  • Exception propagation with type and message verification
  • Multiple invocations demonstrating transformation consistency
  • Complex transformations returning arrays
  • Null return value handling

The tests effectively cover both normal and edge case scenarios for function transformation with checked exception support.

src/test/java/org/zeplinko/commons/lang/ext/util/function/ThrowingBiConsumerTest.java (1)

1-54: Well-designed test suite for ThrowingBiConsumer!

The tests effectively validate the ThrowingBiConsumer interface with:

  • Two-parameter consumption using Map operations
  • Null value handling for both parameters, including HashMap's null key support
  • Checked exception propagation with proper type assertions
  • Multiple invocations demonstrating correct accumulation behavior

The use of map::put as a method reference is particularly elegant for testing bi-consumer behavior.

src/test/java/org/zeplinko/commons/lang/ext/util/function/ThrowingBiFunctionTest.java (1)

1-58: Comprehensive test suite for ThrowingBiFunction!

The tests thoroughly validate the ThrowingBiFunction interface with:

  • Two-parameter function combination using method references (Integer::sum)
  • Comprehensive null handling covering all three scenarios (both null, first null, second null)
  • Exception propagation with proper type verification
  • Multiple invocations with different input pairs
  • Null return value handling

The null handling test (lines 18-32) is particularly thorough, testing all permutations of null inputs with appropriate conditional logic.


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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements throwing functional lambdas by introducing six new functional interfaces that allow checked exceptions to be thrown, mirroring Java's standard functional interfaces but with exception-handling capabilities.

  • Adds six new throwing functional interfaces: ThrowingSupplier, ThrowingRunnable, ThrowingFunction, ThrowingConsumer, ThrowingBiFunction, and ThrowingBiConsumer
  • Each interface includes comprehensive Javadoc documentation with usage context
  • Comprehensive test coverage for all interfaces with multiple test scenarios per interface

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
ThrowingSupplier.java Defines a Supplier-like interface that allows get() to throw checked exceptions
ThrowingRunnable.java Defines a Runnable-like interface that allows run() to throw checked exceptions
ThrowingFunction.java Defines a Function-like interface that allows apply() to throw checked exceptions
ThrowingConsumer.java Defines a Consumer-like interface that allows accept() to throw checked exceptions
ThrowingBiFunction.java Defines a BiFunction-like interface that allows apply() to throw checked exceptions
ThrowingBiConsumer.java Defines a BiConsumer-like interface that allows accept() to throw checked exceptions
ThrowingSupplierTest.java Comprehensive tests for ThrowingSupplier including exception propagation scenarios
ThrowingRunnableTest.java Comprehensive tests for ThrowingRunnable including side effects and exception handling
ThrowingFunctionTest.java Comprehensive tests for ThrowingFunction with various transformation scenarios
ThrowingConsumerTest.java Comprehensive tests for ThrowingConsumer with multiple consumption scenarios
ThrowingBiFunctionTest.java Comprehensive tests for ThrowingBiFunction with null handling and exception propagation
ThrowingBiConsumerTest.java Comprehensive tests for ThrowingBiConsumer with map operations and null value handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/java/org/zeplinko/commons/lang/ext/util/function/ThrowingBiConsumer.java Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ShivamNagpal ShivamNagpal marked this pull request as ready for review November 13, 2025 20:31
@a-anand-91119
Copy link
Copy Markdown
Contributor

@ShivamNagpal We can use the throwing supplier to support try with resources.

something like

Try.withResource(
    ThrowingSupplier<R1> resourceSupplier,
    ThrowingFunction<T> tryBlockContent
);

@a-anand-91119 a-anand-91119 merged commit f2970a5 into develop Nov 23, 2025
9 checks passed
@a-anand-91119 a-anand-91119 deleted the 95-throwable-functional-lambdas branch November 23, 2025 07:15
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