Skip to content

itzephir/Result

Repository files navigation

Result

Overview

This is a custom result library that can be used in case where developer needs to process many different errors. Result can be simply transformed, integrated with kotlin.Result

Docs:

Examples:

fun fetch(): Result<String, Error> {
    // some fetching
    return Result.Success<String>("success")
}

fun uploadToStorage(data: Int): Result<Unit, Error> {
    // some uploading
    return Result.success(Unit)
}

fun fetchAndUploadToStorage(): Result<Unit, Error> {
    return fetch().map {
        it.toInt()
    }.flatMap {
        uploadToStorage(it)
    }
}

fun ooops(): Result<String, Error> {
    // some failed functionality
    return Result.Failure<String>("some failure")
}

fun main() {
    fetchAndUploadToStorage()
        .onSuccess {
            println("success")
        }.onFailure {
            println("error $it")
        }
        .flatMap {
            ooops()
        }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages