result4k

A Result monad for Kotlin, inspired by Rust's Result type

APACHE-2.0 License

Stars
57

Result4K

NB Result4K is moving - please migrate to https://github.com/fork-handles/forkhandles/tree/trunk/result4k

Type safe error handling in Kotlin.

Motivation

Kotlin does not type-check exceptions. Result4k lets you type-check code that reports and recovers from errors.

A Result<T,E> represents the result of a calculation of a T value that might fail with an error of type E.

You can use a when expression to determine if a Result represents a success or a failure, but most of the time you don't need to. Result4k type provides many useful operations for handling success or failure without explicit conditionals.

Result4k works with the grain of the Kotlin language. Kotlin does not have language support for monads (known as "do notation" or "for comprehensions" in other languages). A pure monadic approach becomes verbose and awkward. Therefore, Result4k lets you use early returns to avoid deep nesting when propagating errors.

Package Rankings
Top 27.19% on Repo1.maven.org
Badges
Extracted from project README
Kotlin Build Status Maven Central