Core utilities for Android apps - Result types, error handling, and mappers.
Add GitHub Packages repository to your settings.gradle.kts:
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven {
url = uri("https://maven.pkg.github.com/Zlurgg/core")
credentials {
username = providers.gradleProperty("gpr.user").orNull
password = providers.gradleProperty("gpr.key").orNull
}
}
}
}Add dependency to your build.gradle.kts:
dependencies {
implementation("io.github.zlurgg:core:1.0.0")
}GitHub Packages requires authentication even for public packages. Create a Personal Access Token (PAT) with read:packages scope and add to ~/.gradle/gradle.properties:
gpr.user=YOUR_GITHUB_USERNAME
gpr.key=YOUR_PERSONAL_ACCESS_TOKENType-safe error handling without exceptions:
sealed interface Result<out D, out E : Error> {
data class Success<out D>(val data: D) : Result<D, Nothing>
data class Error<out E : io.github.zlurgg.core.domain.error.Error>(val error: E) : Result<Nothing, E>
}Typed error hierarchy for local and remote operations:
sealed interface DataError : Error {
enum class Local : DataError { DISK_FULL, NOT_FOUND, PERMISSION_DENIED, UNKNOWN }
enum class Remote : DataError { NO_INTERNET, SERVER_ERROR, TIMEOUT, NOT_FOUND, UNKNOWN }
}Maps exceptions to typed DataErrors:
val result = ErrorMapper.safeSuspendCall(TAG) {
// your code that might throw
}Converts DataErrors to user-friendly messages:
val message = ErrorFormatter.format(error, "loading data")
// "Unable to loading data: No internet connection"MIT License