An open API service indexing awesome lists of open source software.

https://github.com/ashr123/exceptional-functions

A collection of functions that protect against unchecked Exceptions
https://github.com/ashr123/exceptional-functions

functional-programming java

Last synced: 2 months ago
JSON representation

A collection of functions that protect against unchecked Exceptions

Awesome Lists containing this project

README

          

# exceptional-functions

[![Maven Central](https://img.shields.io/maven-central/v/io.github.ashr123/exceptional-functions.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22io.github.ashr123%22%20AND%20a:%22exceptional-functions%22)

A collection of functions that protect against unchecked Exceptions.

Code example:

```java
import io.github.ashr123.exceptional.functions.ThrowingFunction;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;

public class Example {
public static Stream exampleWithCasting() {
return Stream.of(
"https://www.google.com",
"https://www.ynet.co.il",
"https://www.stackoverflow.com"
)
.map(URI::create)
.map((ThrowingFunction) URI::toURL)
.map((ThrowingFunction) URL::openStream);
}

public static Stream exampleWithCastingAndWildcards() {
return Stream.of(
"https://www.google.com",
"https://www.ynet.co.il",
"https://www.stackoverflow.com"
)
.map(URI::create)
.map((ThrowingFunction) URI::toURL)
.map((ThrowingFunction) URL::openStream);
}

public static Stream exampleWithCallingUnchecked() {
return Stream.of(
"https://www.google.com",
"https://www.ynet.co.il",
"https://www.stackoverflow.com"
)
.map(URI::create)
.map(ThrowingFunction.unchecked(URI::toURL))
.map(ThrowingFunction.unchecked(URL::openStream));
}

public static R doSomeAction(URL url, ThrowingFunction action) throws T {
return action.applyThrows(url);
}
}
```