# Introduction

<picture><source srcset="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-0f21170996b221cdf3b1e2e6af64d4c496f940fe%2Fresult-logo.dark.svg?alt=media" media="(prefers-color-scheme: dark)"><img src="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-0a47d42244b53b23052663b79bf353283bf0678e%2Fresult-logo.svg?alt=media" alt=""></picture>

## Handle success and failure in Java without exceptions

Wave goodbye to slow exceptions and embrace clean, efficient error handling by encapsulating operations that may succeed or fail in a type-safe way.

<a href="docs/start" class="button primary" data-icon="rocket-launch">Start here</a> <a href="https://github.com/LeakyAbstractions/result" class="button secondary" data-icon="github">Fork me on GitHub</a>

{% hint style="success" %}
Result is a Java library for modeling operation outcomes explicitly. It gives you a simpler, faster alternative to exception-driven flow when you want to represent both success and failure in a single, composable type.
{% endhint %}

### Why Result?

Optional is great for values that may be present or absent, but it does not explain **why** something is missing. Result fills that gap by carrying either a successful value or a failure reason, so your code can describe what happened instead of hiding it.

<div data-full-width="true"><picture><source srcset="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-1ec53057304c1ae6044abab9845a2ebefeb7b88b%2Fmental-model.dark.svg?alt=media" media="(prefers-color-scheme: dark)"><img src="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-7971ec70767a83d6766acefe79191b44819bef3b%2Fmental-model.svg?alt=media" alt="Mental Model"></picture></div>

### Quick Start

{% stepper %}
{% step %}
**Create a result from an operation**

```java
Result<User, Exception> result = Results.ofCallable(() -> db.getUser(id));
```

{% endstep %}

{% step %}
**Inspect whether it succeeded or failed**

```java
result.ifFailure(error -> logger.error("Couldn't get user: {}", id, error));
```

{% endstep %}

{% step %}
**Transform it if needed, then unwrap it as required**

```java
String name = result.mapSuccess(User::name).orElse("Anonymous");
```

{% endstep %}
{% endstepper %}

### Latest Releases

Available in [![Maven Central repository](https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2FtxlH7FxQGh58wxNhEh3T%2Flogo-maven-central.svg?alt=media\&token=fd080dda-c1a1-4679-b6ff-a7d2184e5b12)](https://central.sonatype.com/artifact/com.leakyabstractions/result/)

<table data-card-size="large" data-view="cards" data-full-width="false"><thead><tr><th align="center"></th><th align="center"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td align="center"><strong>Works with</strong></td><td align="center"><picture><source srcset="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fxif2fN7yx1BMJqu9vaS8%2Flogo-maven.dark.svg?alt=media&#x26;token=a93c4b41-233e-452b-9856-14e3915f9807" media="(prefers-color-scheme: dark)"><img src="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2FMi2S8tFmj71pETLI3y1q%2Flogo-maven.svg?alt=media&#x26;token=06775086-fc8c-473b-82ce-6ce94c4d69ad" alt="Maven" data-size="original"></picture></td><td><a href="../docs/start/adding-dependency#maven">#maven</a></td></tr><tr><td align="center"><strong>Works with</strong></td><td align="center"><picture><source srcset="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2FYGExjPQG6IqBloETpgOD%2Flogo-gradle.dark.svg?alt=media&#x26;token=6a5f1e6f-3e8f-4d03-affc-6b980140cc3c" media="(prefers-color-scheme: dark)"><img src="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2FLB7k99sphYsbAP8dv3jU%2Flogo-gradle.svg?alt=media&#x26;token=c0af3fa4-e390-4f58-9527-213f083ea564" alt="Gradle" data-size="original"></picture></td><td><a href="../docs/start/adding-dependency#gradle">#gradle</a></td></tr></tbody></table>

{% tabs %}
{% tab title="Maven" %}

```xml
<dependencies>
    <dependency>
        <groupId>com.leakyabstractions</groupId>
        <artifactId>result</artifactId>
        <version>1.0.0.0</version>
    </dependency>
</dependencies>
```

{% endtab %}

{% tab title="Gradle" %}

```groovy
dependencies {
    implementation("com.leakyabstractions:result:1.0.0.0")
}
```

{% endtab %}
{% endtabs %}

### Add-Ons

Integrate Result with popular libraries.

<table data-card-size="large" data-view="cards"><thead><tr><th align="center"></th><th align="center"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td align="center"><strong>Assert results fluently with</strong></td><td align="center"><picture><source srcset="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-9b4e6cc5040e22ffb5d0c11cc4f395567a14ae1f%2Flogo-assertj.dark.svg?alt=media" media="(prefers-color-scheme: dark)"><img src="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-3257912f982a7815fc77e268942fad62fcde1117%2Flogo-assertj.svg?alt=media" alt="AssertJ" data-size="original"></picture></td><td><a href="add-ons/assertj">assertj</a></td></tr><tr><td align="center"><strong>Serialize results to JSON with</strong></td><td align="center"><picture><source srcset="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-60d50d4bed6180dfeb355f20fbfcd726f04af819%2Flogo-jackson.dark.svg?alt=media" media="(prefers-color-scheme: dark)"><img src="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-5424e7ee1193c6143e29626a5f63437898a3b5e1%2Flogo-jackson.svg?alt=media" alt="Jackson" data-size="original"></picture></td><td><a href="add-ons/jackson">jackson</a></td></tr></tbody></table>

### Demo Projects

Try it for yourself in 5 minutes.

<table data-card-size="large" data-view="cards"><thead><tr><th align="center"></th><th align="center"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td align="center"><strong>Works with</strong></td><td align="center"><img src="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-615cc1d0c9cb3055ba3668a5fa859a4d47619c14%2Flogo-spring.svg?alt=media" alt="Spring Boot" data-size="original"></td><td><a href="extra/demo/spring-boot">spring-boot</a></td></tr><tr><td align="center"><strong>Works with</strong></td><td align="center"><picture><source srcset="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-6d28e45f1e2bfaf8a39419b9c6da150861af8213%2Flogo-micronaut.dark.svg?alt=media" media="(prefers-color-scheme: dark)"><img src="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-1ebd3a4c92eadfb4f0ec40dd68253e8717b354d7%2Flogo-micronaut.svg?alt=media" alt="Micronaut" data-size="original"></picture></td><td><a href="extra/demo/micronaut">micronaut</a></td></tr></tbody></table>

### Features

<table data-view="cards"><thead><tr><th align="center"></th><th align="center"></th><th align="center"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td align="center"><picture><source srcset="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-7a68face31f3e9a1f3343b10e05f822bfe3c9456%2Ftachometer-alt.dark.svg?alt=media" media="(prefers-color-scheme: dark)"><img src="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-725aa7cc28266e34222793f1f6632343a01676a4%2Ftachometer-alt.svg?alt=media" alt="Because exceptions are so last century."></picture></td><td align="center"><strong>Boost Performance</strong></td><td align="center">Avoid exception overhead and benefit from faster operations</td><td><a href="extra/benchmarks">benchmarks</a></td></tr><tr><td align="center"><picture><source srcset="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-79f442d6d9339fab7d22516e47efa00c1f9a6ed6%2Ftint.dark.svg?alt=media" media="(prefers-color-scheme: dark)"><img src="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-572e2790e2a6e3bd0dc6e5b766a3ab2831f4ceea%2Ftint.svg?alt=media" alt="For a smooth ride from Optional to Result."></picture></td><td align="center"><strong>Simple API</strong></td><td align="center">Leverage a familiar interface for a smooth learning curve</td><td><a href="docs/start">start</a></td></tr><tr><td align="center"><picture><source srcset="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-7b388705214a0139596e5d32d1443e8274e1af22%2Fbolt.dark.svg?alt=media" media="(prefers-color-scheme: dark)"><img src="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-c1cce6b90fc0c12e81ccc64a1945e825ddf75623%2Fbolt.svg?alt=media" alt="Say goodbye to error-handling acrobatics."></picture></td><td align="center"><strong>Streamlined Error Handling</strong></td><td align="center">Handle failure explicitly to simplify error propagation</td><td><a href="docs/advanced/screening">screening</a></td></tr><tr><td align="center"><picture><source srcset="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-c1650ac0f59befab10f18c86de69236e66c41bdc%2Fshield-alt.dark.svg?alt=media" media="(prefers-color-scheme: dark)"><img src="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-4f6c6e9a0b07b31dbf0df6f7827456017bb4d31f%2Fshield-alt.svg?alt=media" alt="Skip the exception rollercoaster and enjoy the smooth ride."></picture></td><td align="center"><strong>Safe Execution</strong></td><td align="center">Ensure safer and more predictable operation outcomes</td><td><a href="docs/basic/checking">checking</a></td></tr><tr><td align="center"><picture><source srcset="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-e6692fc8a728bcf1f27afc4ce19a05998642e6bd%2Fglasses.dark.svg?alt=media" media="(prefers-color-scheme: dark)"><img src="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-782869bcc584590736a893adf5bc8c3c7dbd750e%2Fglasses.svg?alt=media" alt="So you can actually understand your own code next month."></picture></td><td align="center"><strong>Enhanced Readability</strong></td><td align="center">Reduce complexity to make your code easier to understand</td><td><a href="docs/basic/conditional">conditional</a></td></tr><tr><td align="center"><picture><source srcset="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-7cbb13d905e9c2b609a0969abd2063ffb67b36a2%2Ffilter.dark.svg?alt=media" media="(prefers-color-scheme: dark)"><img src="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-d4806b9bb7c6220a98e88d9b1dfed63fd964e09c%2Ffilter.svg?alt=media" alt="For those who prefer elegance over chaos."></picture></td><td align="center"><strong>Functional Style</strong></td><td align="center">Embrace elegant, functional programming paradigms</td><td><a href="docs/advanced/transforming">transforming</a></td></tr><tr><td align="center"><picture><source srcset="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-13dd485f33742f709909ac137919a2dc8f0c42c9%2Ffeather-alt.dark.svg?alt=media" media="(prefers-color-scheme: dark)"><img src="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-5cd052a29d1c7c121b4f5127164ff60016498239%2Ffeather-alt.svg?alt=media" alt="Because bloated libraries are so overrated."></picture></td><td align="center"><strong>Lightweight</strong></td><td align="center">Keep your project slim with no extra dependencies</td><td><a href="docs/start/adding-dependency">adding-dependency</a></td></tr><tr><td align="center"><picture><source srcset="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-b6ea70bff16c9f1e3d629f0857bb2c0d4ffb9815%2Fbalance-scale.dark.svg?alt=media" media="(prefers-color-scheme: dark)"><img src="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-e69b8c72c9e9f96f02e45d5e3926e69d712c0500%2Fbalance-scale.svg?alt=media" alt="Feel free to tweak and share — no strings attached."></picture></td><td align="center"><strong>Open Source</strong></td><td align="center">Enjoy transparent, permissive Apache 2 licensing</td><td><a href="extra/license">license</a></td></tr><tr><td align="center"><picture><source srcset="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-1cce85eb136a1fef925c02cadd99104069087e83%2Fmug-hot.dark.svg?alt=media" media="(prefers-color-scheme: dark)"><img src="https://137539276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfavUYGNGvzkCicVu3-%2Fuploads%2Fgit-blob-5710b36fc6879babe50d87fe5c04c56b2b7acb8d%2Fmug-hot.svg?alt=media" alt="Whether you&#x27;re stuck in the past or embracing the future, we&#x27;ve got you covered."></picture></td><td align="center"><strong>Pure Java</strong></td><td align="center">Seamless compatibility from JDK8 to the latest versions</td><td><a href="https://github.com/LeakyAbstractions/result/">https://github.com/LeakyAbstractions/result/</a></td></tr></tbody></table>

### Ready to Tap into the Power of Results?

Read the guide and transform your error handling today.

{% content-ref url="docs/start" %}
[start](https://result.leakyabstractions.com/docs/start)
{% endcontent-ref %}

{% content-ref url="docs/basic" %}
[basic](https://result.leakyabstractions.com/docs/basic)
{% endcontent-ref %}

{% content-ref url="docs/advanced" %}
[advanced](https://result.leakyabstractions.com/docs/advanced)
{% endcontent-ref %}

Also available as an **ebook** in multiple formats. [Download your free copy now!](https://leanpub.com/result/)

### TL;DR

Not a fan of reading long docs? No worries! Tune in to *Deep Dive*, a podcast generated by [NetbookLM](https://notebooklm.google.com/). In just a few minutes, you'll get the essential details and a fun intro to what this library can do for you!

{% embed url="<https://www.youtube.com/watch?v=sTBRnm0KosM>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://result.leakyabstractions.com/readme.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
