A multiplatform Result monad for modelling success or failure operations.
be2fa210cc
Matches Haskell's Either.fromRight |
||
---|---|---|
gradle/wrapper | ||
src | ||
.editorconfig | ||
.gitignore | ||
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 (Error
) 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:
- Relaxed constraints on nullable types (both the
value
anderror
can be typed as nullable) - Relaxed constraints on the
error
type to not inherit fromException
- Top level
Ok
andError
classes avoids qualifying usages withResult.Ok
/Result.Error
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 and every library method covered
Installation
This project is available in the Maven Central Repository repository. The artifacts are signed with my personal GPG key.
repositories {
mavenCentral()
}
dependencies {
compile 'com.mikebull94.kotlin-result:kotlin-result:1.0.0'
}