NB Result4K is moving - please migrate to https://github.com/fork-handles/forkhandles/tree/trunk/result4k
Type safe error handling in Kotlin.
Kotlin does not type-check exceptions. Result4k lets you type-check code that reports and recovers from errors.
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.