A multiplatform Result monad for modelling success or failure operations.
e455be2cc8
When constructing the exception message the toString method will be implicitly called on the result of the lambda. Takes inspiration from Kotlin's require function [1]. [1]: https://github.com/JetBrains/kotlin/blob/v1.2.0/libraries/stdlib/src/kotlin/util/Preconditions.kt#L26 |
||
---|---|---|
gradle/wrapper | ||
src | ||
.editorconfig | ||
.gitignore | ||
.travis.yml | ||
build.gradle | ||
gradle.properties | ||
gradlew | ||
gradlew.bat | ||
LICENSE | ||
README.md | ||
settings.gradle |
kotlin-result
Result<V, E>
is a monad for modelling success (Ok
) or
failure (Err
) operations.
Inspiration
Inspiration for this library has been drawn from other languages in which the Result monad is present, including:
It also iterates on other Result libraries written in Kotlin, namely:
Improvements on the existing solutions include:
- Feature parity with Result types from other languages including Elm, Haskell, & Rust
- Lax constraints on
value
/error
nullability - Lax constraints on the
error
type's inheritance (does not inherit fromException
) - Top level
Ok
andErr
classes avoids qualifying usages withResult.Ok
/Result.Err
respectively - Higher-order functions marked with the
inline
keyword for reduced runtime overhead - Extension functions on
Iterable
&List
for folding, combining, partitioning - Consistent naming with existing Result libraries from other languages (e.g.
map
,mapError
,mapBoth
,mapEither
,and
,andThen
,or
,orElse
,unwrap
) - Extensive test suite with over 50 unit tests covering every library method
Installation
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.github.michaelbull:kotlin-result:1.0.1'
}
Getting Started
The unit tests are a good source of examples for using the library as they cover every available method.
Mappings from common Result libraries are available on the wiki:
Contributing
Bug reports and pull requests are welcome on GitHub.
License
This project is available under the terms of the ISC license. See the
LICENSE
file for the copyright information and licensing terms.