Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# Checked-Exceptions-enabled Java 8+ Functional Interfaces
and adapters

[![Build against JDKs](https://github.com/pivovarit/throwing-function/actions/workflows/build.yml/badge.svg)](https://github.com/pivovarit/throwing-function/actions/workflows/build.yml)
[![License](http://img.shields.io/:license-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.pivovarit/throwing-function/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.pivovarit/throwing-function)

[![Stargazers over time](https://starchart.cc/pivovarit/throwing-function.svg?variant=adaptive)](https://starchart.cc/pivovarit/throwing-function)

## Rationale
## Overview

Standard `java.util.function` Functional Interfaces aren't checked-exception-friendly due to the absence of `throws ...` clause which results in tedious and verbose necessity of handling them by adding `try-catch` boilerplate.
Java’s standard `java.util.function` interfaces are not compatible with checked exceptions. This leads to verbose and cluttered code, requiring manual try-catch blocks for exception handling, which makes one-liners like this:

Which makes one-liners like this:
```
path -> new URI(path)
```
Expand All @@ -27,17 +25,17 @@ path -> {
}
```

By applying `com.pivovarit.function` functional interfaces, it's possible to regain clarity and readability:
This library introduces checked-exception-enabled functional interfaces, like `ThrowingFunction`, allowing cleaner, more concise code. You can now handle exceptions in functional pipelines without sacrificing readability:

ThrowingFunction<String, URI, URISyntaxException> toUri = URI::new;

and use them seamlessly with native `java.util.function` classes by using custom `ThrowingFunction#unchecked` adapters:
Using the `ThrowingFunction#unchecked` adapter, this can be seamlessly integrated into standard streams:

...stream()
.map(unchecked(URI::new)) // static import of ThrowingFunction#unchecked
.forEach(System.out::println);

which avoids ending up with:
This eliminates the need for bulky try-catch blocks within stream operations:

...stream().map(path -> {
try {
Expand All @@ -46,7 +44,13 @@ which avoids ending up with:
throw new RuntimeException(e);
}}).forEach(System.out::println);

### Basic API
### Key Features

- Functional Interfaces: Supports various functional types with checked exceptions.
- Adapters: Provides utility methods to convert `Throwing*` types into standard Java functional interfaces.
- Lightweight: No external dependencies, implemented using core Java libraries.

### Core API

#### Functional Interfaces

Expand Down Expand Up @@ -95,6 +99,10 @@ None - the library is implemented using core Java libraries.

## Version history

## [1.6.0 (24-09-2024)](https://github.com/pivovarit/throwing-function/releases/tag/1.6.0)

* Added `Automatic-Module-Name` to MANIFEST

### [1.5.1 (06-05-2020)](https://github.com/pivovarit/throwing-function/releases/tag/1.5.1)

* Fixed visibility issues with `ThrowingIntFunction`
Expand Down