All Projects → npryce → result4k

npryce / result4k

Licence: Apache-2.0 License
A Result monad for Kotlin, inspired by Rust's Result type

Programming Languages

kotlin
9241 projects
shell
77523 projects

Result4K

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

Kotlin Build Status Maven Central

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].