Skip to content

aDudko/safe-java-streams

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Safe Java Streams

build release license issues stars

Java Built with Maven Javadoc Coverage GitHub Packages


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/catch in Stream API
  • Handle errors without exceptions using Either / Result
  • Represent computations that may fail using Try
  • Bridge Java's checked exceptions into functional pipelines

πŸ“¦ Project Setup (Maven)

1. Add GitHub Packages repository

<repositories>
  <repository>
    <id>github</id>
    <name>GitHub Packages</name>
    <url>https://maven.pkg.github.com/aDudko/safe-java-streams</url>
  </repository>
</repositories>

2. Add dependency

<dependency>
  <groupId>io.github.aDudko</groupId>
  <artifactId>safe-java-streams</artifactId>
  <version>1.0.0</version>
</dependency>

πŸ” Key Features

βœ… Either<L, R>

A disjoint union of Left and Right, representing success or error.

  • map, flatMap, fold, toOptional
  • recover, recoverWith, peek
  • getOrElse, orElseThrow

πŸ”„ Try<T>

Encapsulates a computation that may fail:

  • Success or Failure
  • Fluent chaining with map, flatMap, recover
  • Transform to Optional / Either

πŸ“Š Result<T, E>

Inspired by Rust/Scala. Encapsulates success or failure with separate types:

  • map, flatMap, mapError, recover
  • get, getOrElse, toEither, toOptional

🧰 CheckedAdapters

Adapter utilities for using checked-exception-throwing lambdas in Stream API:

  • wrapFunction, wrapConsumer, wrapSupplier etc.
  • safeFunctionOptional, safeFunctionEither

πŸ’‘ Usage Examples


πŸ§ͺ Test Coverage

  • Tests written with JUnit 5
  • Covers all core features: Either, Try, Result, CheckedAdapters

πŸ“˜ JavaDoc

πŸ‘‰ Browse Online Documentation


πŸš€ Roadmap

  • Add Try<T> and Result<T, E>
  • Improve error handling ergonomics
  • Add Validated and NonEmptyList
  • Add monadic and DSL-style builders
  • Gradle & Kotlin support

If you find this useful...

...give it a star, fork it, or mention it in your next data project!

✍️ Author

Anatoly Dudko
GitHub @aDudko β€’ LinkedIn

About

Adds functional utilities for exception handling and value processing, enabling cleaner, safer and more predictable code

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages