{"id":13607293,"url":"https://github.com/Subito-it/Esito","last_synced_at":"2025-04-12T11:32:07.616Z","repository":{"id":73390337,"uuid":"424229980","full_name":"Subito-it/Esito","owner":"Subito-it","description":"Esito ambition is to be your return type for suspending functions.","archived":true,"fork":false,"pushed_at":"2024-07-19T14:42:49.000Z","size":82,"stargazers_count":58,"open_issues_count":4,"forks_count":1,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-11-07T12:44:20.200Z","etag":null,"topics":["android","functional-programming","kotlin","result","retrofit"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Subito-it.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-03T13:15:41.000Z","updated_at":"2024-08-17T20:24:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"e295ce63-a6cb-4a4a-814b-432e37be69fd","html_url":"https://github.com/Subito-it/Esito","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Subito-it%2FEsito","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Subito-it%2FEsito/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Subito-it%2FEsito/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Subito-it%2FEsito/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Subito-it","download_url":"https://codeload.github.com/Subito-it/Esito/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248560189,"owners_count":21124609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","functional-programming","kotlin","result","retrofit"],"created_at":"2024-08-01T19:01:17.370Z","updated_at":"2025-04-12T11:32:03.171Z","avatar_url":"https://github.com/Subito-it.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"# Esito - Deprecated\n\n## ⛔️ DEPRECATED\n\nWe have chosen to stop support and improvements on Esito since we internally migrated to [Arrow](https://arrow-kt.io/). When Esito was created (at the beginning of 2021), Arrow was still in progress and was not stable at all ([version 1.0.0](https://github.com/arrow-kt/arrow/releases/tag/1.0.0) was released in September 2021). Basically, using Arrow, you can achieve the same results and also explore functional programming more, if you like!\n\n\n[![](https://jitpack.io/v/Subito-it/Esito.svg)](https://jitpack.io/#Subito-it/Esito)\n\nCoroutines are great for Asynchronous and non-blocking programming, but exceptions could be hard to handle, especially in a coroutine. [[1](https://kt.academy/article/cc-exception-handling), [2](https://medium.com/androiddevelopers/exceptions-in-coroutines-ce8da1ec060c), [3](https://www.netguru.com/blog/exceptions-in-kotlin-coroutines)]\n\nExceptions in a coroutine could cancel their parents, and each canceled parent cancels all its children, and this is not always the desired behavior.\n\nWhile this could be changed using a `SupervisorJob`, it's still easy to shoot yourself in the foots throwing exceptions in Coroutines, so Esito is proposing an alternative approach making explicit the computations that could fail.\n\n## Installation\n\n```groovy\nrepositories {\n\tmaven { url 'https://jitpack.io' }\n}\n\ndependencies {\n    implementation(\"com.github.Subito-it.Esito:core:(insert latest version)\")\n}\n```\n\n### Getting started\n\nThe main class is the sealed class [`Result`](core/src/main/kotlin/it/subito/esito/core/Result.kt), with two subtypes:\n\n - `Success`: it contains the result of a successful computation\n - `Failure`: it contains the cause of an unsuccessful computation\n\nThe goal when using Esito is to avoid throwing exceptions and use Result as the return type of a function that can fail:\n\n\n```kotlin\nsealed class ConversionError\nobject EmptyInput : ConversionError()\nobject NotNumericInput : ConversionError()\n\nfun fromStringToInt(input: String): Result\u003cInt, ConversionError\u003e = when {\n    input.isBlank() -\u003e Result.failure(EmptyInput)\n    else -\u003e runCatching { input.toInt() }.mapError { NotNumericInput }\n}\n```\n\nIn this example we are defining all the possible failures in `ConversionError`, then we are applying some logic to build our result.\n\nIf the input is not blank we are using the `runCatching` method to wrap a method throwing an exception and mapping the eventual error in our desired type.\n\n### Operators\n\nEsito result has several operators, such as `map` and `flatmap`, for examples see [Recipes](Recipes.md).\n\n## Retrofit Integration\n\nEsito ships an integration with retrofit, after a one-line setup you can start to use Result return type in your Retrofit interfaces:\n\n```kotlin\ninterface GitHubService {\n    \n    @GET(\"users/{user}/repos\")\n    suspend fun listRepos(@Path(\"user\") user: String?): Result\u003cList\u003cRepo\u003e, Throwable\u003e\n}\n```\n\nFor additional info and to learn how to use your own Error instead of Throwable have a look at [this documentation](/retrofit/README.md).\n\n## Async Utilities\n\nEsito offers some utilities for suspending methods returning Result. For example, suppose we have the following functions:\n\n```kotlin\nsuspend fun getUserFullName(userId: Int): Result\u003cString, FeatureError\u003e\n\nsuspend fun getUserStatus(userId: Int): Result\u003cUserStatus, FeatureError\u003e\n\n```\n\nAnd we have to return an instance of DataForUI running in parallel `getUserFullName` and `getUserStatus`.\n\n```kotlin\ndata class DataForUI(\n\tval userFullName: String,\n\tval userStatus: UserStatus\n)\n```\n\nEsito exposes a `zip` method to compute two independent execution in parallel:\n\n```kotlin\nsuspend fun fetchIfo(userId: Int): Result\u003cDataForUI, FeatureError\u003e =\n\tzip(\n\t\t{ getUserFullName(userId) },\n\t\t{ getUserStatus(userId) },\n\t\t::DataForUI //syntactic sugar for constructor\n\t\t).invoke()\n```\nFor additional info have a look at this [documentation](async/README.md).\n\n## Testing\n\nEsito is providing two extension methods to facilitate testing: `assertIsSuccess` and `assertIsFailure`, here is an example of usage:\n\n```kotlin\nval success = Result.success\u003cInt, Throwable\u003e(42)\nsuccess.assertIsSuccess {\n    assertEquals(42, value)\n}\n\nval failure = Result.failure\u003cInt, RuntimeException\u003e(RuntimeException(\"Ops\"))\nfailure.assertIsFailure {\n    assertEquals(\"Ops\", error.message)\n}\n```\nFor additional info have a look at this [documentation](test/README.md).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSubito-it%2FEsito","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSubito-it%2FEsito","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSubito-it%2FEsito/lists"}