Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/archenoth/result
A destructurable Rust-style Result type for Java!
https://github.com/archenoth/result
destructuring java null-safety result-type sealed-interface
Last synced: 2 days ago
JSON representation
A destructurable Rust-style Result type for Java!
- Host: GitHub
- URL: https://github.com/archenoth/result
- Owner: Archenoth
- License: epl-1.0
- Created: 2024-01-15T05:57:37.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-01-15T05:59:05.000Z (12 months ago)
- Last Synced: 2024-11-08T10:08:49.457Z (about 2 months ago)
- Topics: destructuring, java, null-safety, result-type, sealed-interface
- Language: Java
- Homepage:
- Size: 50.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# A destructurable Result type for Java 21+!
This library is a simple `Result` sealed interface allowing you to eliminate `null` in all kinds of places in a way that [Rustaceans have enjoyed for a long time](https://doc.rust-lang.org/std/result/)~
Meaning you can do things like this!
```java
if(somethingThatReturnsAResult() instanceof Some(File found)){
file.delete();
}
```or this!
```java
return switch(somethingThatReturnsAResult()){
case Some(String message) -> message;
case None() -> "Uh oh, nothing??";
};
```or even this!
```java
return switch(somethingThatReturnsAResult()){
case Some(val num) when num == 1 -> num + " thing";
case Some(val num) -> num + " things!";
case None() -> "Uh oh, nothing??";
};
```All you need to do is wrap your return value with a `Result.of()`. It even works with wrapped `Optional` values!