safe-java-streams is a lightweight Java library that adds functional utilities for exception handling and Either/Try/Result style value processing, enabling cleaner, safer, and more predictable code.
It helps:
- Eliminate boilerplate
try/catchinStream API - Handle errors without exceptions using
Either/Result - Represent computations that may fail using
Try - Bridge Java's checked exceptions into functional pipelines
<repositories>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/aDudko/safe-java-streams</url>
</repository>
</repositories><dependency>
<groupId>io.github.aDudko</groupId>
<artifactId>safe-java-streams</artifactId>
<version>1.0.0</version>
</dependency>A disjoint union of Left and Right, representing success or error.
map,flatMap,fold,toOptionalrecover,recoverWith,peekgetOrElse,orElseThrow
Encapsulates a computation that may fail:
SuccessorFailure- Fluent chaining with
map,flatMap,recover - Transform to
Optional/Either
Inspired by Rust/Scala. Encapsulates success or failure with separate types:
map,flatMap,mapError,recoverget,getOrElse,toEither,toOptional
Adapter utilities for using checked-exception-throwing lambdas in Stream API:
wrapFunction,wrapConsumer,wrapSupplieretc.safeFunctionOptional,safeFunctionEither
💡 Usage Examples
- Tests written with
JUnit 5 - Covers all core features:
Either,Try,Result,CheckedAdapters
- Add
Try<T>andResult<T, E> - Improve error handling ergonomics
- Add
ValidatedandNonEmptyList - Add monadic and DSL-style builders
- Gradle & Kotlin support
...give it a star, fork it, or mention it in your next data project!
Anatoly Dudko
GitHub @aDudko • LinkedIn