KResult


An opinionated, functional Result type for Kotlin
KResult is a functional library that provides an opinionated and feature-rich extension /
alternative to Kotlin's Result<T> type. While the core
library is as lean and dependency-free as possible, seamless integrations with common frameworks are provided via
integration packages or plugins. KResult is heavily inspired by
Scala's type,
Rust's and
Arrow's .
Features
Find full documentation on kresult.io.
Usage
KResult is hosted on Maven Central. Use your favorite build tool to add a dependency. Replace
VERSION with the current version number:
Using Gradle Kotlin DSL:
dependencies {
implementation("io.kresult:kresult-core:VERSION")
}
Using Gradle Groovy DSL:
implementation group: 'io.kresult', name: 'kresult-core', version: 'VERSION'
Using Maven:
<dependency>
<groupId>io.kresult</groupId>
<artifactId>kresult-core</artifactId>
<version>VERSION</version>
</dependency>
Core Modules
Integrations
| Module | Description | Link |
|---|
kresult-arrow | Supports seamless integration with types of the Arrow functional programming library. |
Hello, World
While strings are simple for showcasing, a more real world solution would have strongly typed result values. One common
practice is to encode:
Success side value as a product type (data class in Kotlin)
Failure side value as a sum type / tagged union (enum or sealed class in Kotlin)
The following example demonstrates a very simplified case, where a greeting message is validated for correctness, and
the resulting KResult<Failure, Greeting> is folded to an exemplary Response object again. In a more practical setup,
that Response and the mechanics to produce it would of course be provided by a framework integration:
License
Copyright 2024 kresult.io authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http:
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.