Skip to content

Latest commit

 

History

History
115 lines (80 loc) · 3.23 KB

File metadata and controls

115 lines (80 loc) · 3.23 KB

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 @aDudkoLinkedIn