FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

aDudko/safe-java-streams: Adds functional utilities for exception handling and value processing, enabling cleaner, safer and more predictable code · GitHub

Latest commit

 

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Safe Java Streams


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

About

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

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages


Back | FazBrowse Home | New Git URL