Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/razshare/kotlin-result
A simple standalone utility library for managing unsafe results in Kotlin instead of throwing exceptions.
https://github.com/razshare/kotlin-result
Last synced: 1 day ago
JSON representation
A simple standalone utility library for managing unsafe results in Kotlin instead of throwing exceptions.
- Host: GitHub
- URL: https://github.com/razshare/kotlin-result
- Owner: razshare
- License: mit
- Created: 2023-12-28T14:28:17.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-09T22:12:30.000Z (8 months ago)
- Last Synced: 2025-01-08T15:18:16.805Z (5 days ago)
- Language: Kotlin
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Kotlin Result
This is a simple standalone utility library for managing unsafe results in Kotlin instead of throwing exceptions.
```kt
import dev.razshare.result.Result
import dev.razshare.result.success
import dev.razshare.result.failuredata class User(val username: String, val password: String)
fun validateUser(user: User): Result {
if(user.password.length < 4){
return failure("User password must be at least 4 characters, received ${user.password.length} characters.")
}return success(user)
}fun main(){
val (user, error) = validateUser(User(username = "foo", password = "bar")).unwrap()if(error.isPresent){
println(error.get)
return
}println("User ${user.username} is valid.")
}
```# Using Gradle Kotlin
- Add the repository to your `build.gradle.kts`
```kt
repositories {
maven {
url = uri("https://raw.githubusercontent.com/tncrazvan/artifacts/main")
metadataSources {
mavenPom()
artifact()
ignoreGradleMetadataRedirection()
}
}
}
```- Add the library to your `build.gradle.kts`, for example `dev.razshare.result`
```kt
dependencies {
implementation("dev.razshare:result:0.1.0")
}
```# Using Maven
- Add the repository to your `pom.xml`
```xml
dev.razshare
https://raw.githubusercontent.com/tncrazvan/artifacts/main
```- Add the library to your `pom.xml`, for example `dev.razshare.result`
```xml
dev.razshare
result
0.1.0
jar
```