LogoLogo
GitHubFree book
  • 🏠Introduction
  • Using the Library
    • ðŸŒąGetting Started
      • Adding Result to Your Build
      • Creating Results
    • ðŸŠīBasic Usage
      • Checking Success or Failure
      • Unwrapping Values
      • Conditional Actions
    • 🚀Advanced Usage
      • Screening Results
      • Transforming Results
    • 🏁Recap
  • Add-ons
    • ðŸ’ĪLazy Results
    • ðŸ—ĢïļFluent Assertions
    • 📜Jackson Module
    • 🧑‍🚀Micronaut Serialization
  • Other resources
    • ðŸ“ĶBill of Materials
    • 📈Benchmarks
    • ðŸĪ–Demo Projects
      • Spring Boot Demo Project
      • Micronaut Demo Project
    • ⚖ïļLicense
Powered by GitBook
LogoLogo

Source Code

  • GitHub
  • License

Quality

  • SonarCloud
  • Benchmarks

Documentation

  • Free book
  • Javadoc

Releases

  • Maven Central
  • Bill of Materials

Copyright 2024 Guillermo Calvo

On this page

Was this helpful?

Edit on GitHub
Export as PDF
  1. Using the Library

Getting Started

How to get up and running with Results in no time

PreviousIntroductionNextAdding Result to Your Build

Last updated 7 months ago

Was this helpful?

The best way to think of Results is as a super-powered version of Java's Optionals.

Result builds upon the familiar concept of Optional, enhancing it with the ability to represent both success and failure states.

Optional class is useful for representing values that might be present or absent, eliminating the need for null checks. However, Optionals fall short when it comes to error handling because they do not convey why a value is lacking. Result addresses this limitation by encapsulating both successful values and failure reasons, offering a more expressive way to reason about what went wrong.

Results provide the same methods as Optionals, plus additional ones to handle failure states effectively.

By leveraging Results, you can unleash a powerful tool for error handling that goes beyond the capabilities of traditional Optionals, leading to more robust and maintainable Java code.

ðŸŒą
Optional
Result
isPresent
hasSuccess
isEmpty
hasFailure
get
getSuccess
getFailure
orElse
orElse
orElseGet
orElseMap
stream
streamSuccess
streamFailure
ifPresent
ifSuccess
ifFailure
ifPresentOrElse
ifSuccessOrElse
filter
filter
recover
map
mapSuccess
mapFailure
map
flatMap
flatMapSuccess
or
flatMapFailure
flatMap
No need to return null or throw an exception: just return a failed result.