{"id":21396778,"url":"https://github.com/favware/java-result","last_synced_at":"2025-07-13T19:31:27.297Z","repository":{"id":162821041,"uuid":"612197581","full_name":"favware/java-result","owner":"favware","description":"A Java implementation of a Result monad inspired by Rust's Result struct.","archived":false,"fork":false,"pushed_at":"2024-11-17T00:29:02.000Z","size":3288,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-17T01:22:04.007Z","etag":null,"topics":["java","result"],"latest_commit_sha":null,"homepage":"https://favware.github.io/java-result/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/favware.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["favna"],"patreon":"favna","open_collective":null,"ko_fi":"favna","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":"https://donate.favware.tech/paypal"}},"created_at":"2023-03-10T12:09:57.000Z","updated_at":"2024-11-17T00:29:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"da4a1813-6ccb-4eaa-84ef-24441e1e718a","html_url":"https://github.com/favware/java-result","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favware%2Fjava-result","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favware%2Fjava-result/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favware%2Fjava-result/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favware%2Fjava-result/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/favware","download_url":"https://codeload.github.com/favware/java-result/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225911870,"owners_count":17544055,"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":["java","result"],"created_at":"2024-11-22T14:29:15.797Z","updated_at":"2024-11-22T14:29:16.491Z","avatar_url":"https://github.com/favware.png","language":"Java","funding_links":["https://github.com/sponsors/favna","https://patreon.com/favna","https://ko-fi.com/favna","https://donate.favware.tech/paypal"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# Result\n\n**A Java implementation of a Result monad inspired by Rust's Result struct**\n\n[![GitHub](https://img.shields.io/github/license/favware/java-result)](https://github.com/favware/java-result/blob/main/LICENSE)\n\n[![Support Server](https://discord.com/api/guilds/512303595966824458/embed.png?style=banner2)](https://join.favware.tech)\n\n\u003c/div\u003e\n\n***Important:*** This package is a mirror of https://github.com/jasongoodwin/better-java-monads, however that package is\nnot maintained any more. This way we can maintain the code ourselves. Furthermore, the dependency as pulled in from\nmaven-central was also unable to properly show javadoc comments for unknown reason. Big chunks of the following text are\ntaken straight from the original source code.\n\n---\n\n## About\n\nThis library adds a `Result` monad to Java. While `Optional` exists to express nulls in types, there is no way to\nexpress a success/failure of a callable lambda expression. `Result` fills this gap.\n\nThe `Result` type is very similar to the `Result` in Scala's standard lib. Some inspiration is also taken from\nthe `Result` monad in the Rust language, and subsequently from `@sapphire/result`, the TypeScript implementation of the\nformer.\n\nLastly, this version of the `Result` monad also addresses all open issues in the original project, as well as including\nthe\ncode of all open pull requests.\n\n## Installation\n\n### Maven\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003etech.favware\u003c/groupId\u003e\n    \u003cartifactId\u003eresult\u003c/artifactId\u003e\n    \u003cversion\u003e1.2.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Gradle\n\n**With Gradle Groovy**\n\n```groovy\ndependencies {\n    implementation 'tech.favware:result:1.2.0'\n}\n```\n\n**With Kotlin DSL**\n\n```kotlin\ndependencies {\n    implementation(\"tech.favware:result:1.2.0\")\n}\n```\n\n## Usage\n\nThe `Result` monad was attributed to Twitter and placed into the Scala standard library.\nWhile both Scala and Haskell have a monad Either which has a left and a right type,\na `Result` is specifically of a type `T` on success or an exception on failure.\n\nThe `Result` api is meant to be similar to the `Optional` type so has the same functions.\n\n- `get()` returns the held value or throws the thrown exception\n- `getUnchecked()` returns the held value or throws the thrown exception wrapped in a `RuntimeException` instance\n- `map(x)` maps the success value `x` to a new value and type or otherwise passes the Failure forward.\n- `flatMap((x) -\u003e f(x))` maps the success value `x` to a new `Result` of f(x).\n- `recover((t) -\u003e x)` will return the success value of the `Result` in the success case or the value `x` in the failure\n  case.\n  Exposes the exception.\n- `recoverWith((t) -\u003e f(x))` will return the success value of the `Result` in the success case or a new `Result`\n  of `f(x)` in\n  the\n  failure case. Exposes the exception.\n- `filter((x) -\u003e isTrue(x))` - If `Success`, returns the same `Success` if the predicate succeeds, otherwise, returns a\n  `Failure` with type `NoSuchElementException`.\n- `onSuccess((x) -\u003e f(x))` execute some code on success - takes a `Consumer` (e.g. requires no return value).\n- `onFailure((x) -\u003e f(x))` execute some code on failure - takes a `Consumer` (e.g. requires no return value).\n- `raise(x)` -\u003e will throw an exception of type `x` when it happens.\n- `orElse(x)` will return the success value of the `Result` in success case or the value `x` in failure case.\n- `orElseResult(f)` will return the success value of the `Result` in success case or a new `Result(f)` in the failure\n  case.\n- `orElseThrow(() -\u003e throw new T)` gets result or on failure will throw checked exception of type `T`\n- `toOptional()` will return `Optional` of success value of `Result` (if not `null`), otherwise it will return an\n  empty `Optional`\n- `mapErr(e)` maps the failure value `e` to a new error type or otherwise passes the success forward.\n- `match((x, y)` Takes the result of the `Result` and applies the first function to the success value or the second\n  function to the failure value. Transforms the return type to the return type of the applied function.\n\n## Contributors\n\nPlease make sure to read the [Contributing Guide][contributing] before making a pull request.\n\nThank you to all the people who already contributed to Sapphire!\n\n\u003ca href=\"https://github.com/favware/java-result/graphs/contributors\"\u003e\n  \u003cimg alt=\"contributors\" src=\"https://contrib.rocks/image?repo=favware/java-result\" /\u003e\n\u003c/a\u003e\n\n[contributing]: ./.github/CONTRIBUTING.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffavware%2Fjava-result","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffavware%2Fjava-result","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffavware%2Fjava-result/lists"}