https://github.com/npryce/result4k
A Result monad for Kotlin, inspired by Rust's Result type
https://github.com/npryce/result4k
Last synced: about 1 year ago
JSON representation
A Result monad for Kotlin, inspired by Rust's Result type
- Host: GitHub
- URL: https://github.com/npryce/result4k
- Owner: npryce
- License: apache-2.0
- Created: 2017-08-23T12:56:56.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-10-02T09:37:07.000Z (over 5 years ago)
- Last Synced: 2025-03-27T10:21:16.403Z (about 1 year ago)
- Language: Kotlin
- Homepage:
- Size: 131 KB
- Stars: 59
- Watchers: 5
- Forks: 12
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Result4K
NB Result4K is moving - please migrate to https://github.com/fork-handles/forkhandles/tree/trunk/result4k
[](http://kotlinlang.org)
[](https://travis-ci.org/npryce/result4k)
[](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.natpryce%22%20AND%20a%3A%22result4k%22)
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` 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.