{"id":23508728,"url":"https://github.com/lovasko/result","last_synced_at":"2025-05-13T15:34:41.904Z","repository":{"id":78821055,"uuid":"181780123","full_name":"lovasko/result","owner":"lovasko","description":"Parametric Type to Capture Result of a Computation in Java 8+","archived":false,"fork":false,"pushed_at":"2019-05-19T22:15:28.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-16T19:48:23.954Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lovasko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2019-04-16T23:04:10.000Z","updated_at":"2019-08-08T13:20:20.000Z","dependencies_parsed_at":"2023-05-03T14:47:57.662Z","dependency_job_id":null,"html_url":"https://github.com/lovasko/result","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasko%2Fresult","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasko%2Fresult/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasko%2Fresult/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasko%2Fresult/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lovasko","download_url":"https://codeload.github.com/lovasko/result/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253970410,"owners_count":21992490,"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":[],"created_at":"2024-12-25T11:31:48.064Z","updated_at":"2025-05-13T15:34:41.841Z","avatar_url":"https://github.com/lovasko.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sk.dlo.result\nThe `result` library provides a robust framework for error handling with the\naim of eliminating exceptions and the `null` value.\n\n## Introduction\nThis library intends to change how a program represents and processes\ncomputation results - both success and failure. The cardinal aim is to ensure\nthat all potential failures are readily captured during compile-time and that\nthe programmer is assisted in addressing all potential results of a\ncombination of computations.\n\n### Why not exceptions?\nExceptions are a non-local form of program control, which strongly tie\ntogether two places in the code which might be completely unrelated - the\nplace where the exception was thrown and where it was caught. This makes\nreasoning about the code correctness harder. Moreover, exceptions are designed\nto be used in cases where a situation isn't _exceptional_ at all, such as user\ninput errors or network transmission issues. Runtime exceptions can occur at\nany time without the programmer being able to verify that these were handled -\nsomething that the `result` library finds unacceptable for production-grade\ncode.\n\nThe `result` library enables local access to the result of the computation and\ninspires clear representation of both success and failure cases by requiring\nboth types in the generic type arguments.\n\n### Why avoid `null`?\nThe `null` value is used to represent many facts or circumstances. This leads\nto issues for readers of the code as to what particular purpose the value\nis being used. An example might be a database search, where the result `null`\nmight represent both unavailability of the requested key, or the inability to\nconnect to the remote database system. Moreover, a production-grade code shall\nnot fail due to unexpected `NullPointerException`. This can be partly achieved\nby not returning `null`, but also needs to be accompanied by ever-present\nchecking if each operation in a chain has not returned `null`. This renders\nthe code to be deeply nested and leads to programmer errors due to unhandled\nedge-cases.\n\nThe `result` library offers a simple way how to define various types of\nfailures for a computation, whilst ensuring that a chain of operations is\nhandled correctly. All this is done in a succinct manner. \n\n## Example\nThe following code attempts to connect to either the primary or secondary\ninstance of a service, request data if either of the connections was\nsuccessful, format and print the results to the user. An error is logged in\ncase any of these steps failed. \n\n```java\nconnectToPrimary()\n  .orElse(connectToSecondary)\n  .andThen(selectData)\n  .andThen(formatDataTable)\n  .conclude(printDataTable, logError);\n```\n\nIt is crucial to recognise that this approach combines multiple design\npatterns: alternative data sources with `orElse`, lazy execution of chained \noperations with `andThen`, and compulsory confrontation of both success and\nfailure of the computation with `conclude` .\n\nThe assumption made is that methods `connectToPrimary`,\n`connectToSecondary`, `selectData`, and `formatDataTable` return\ntype-compatible `Result` instances. Furthermore, functions `printDataTable`\nand `logError` are expected to work directly on non-null values, whilst\nobeying the requirement that any failure is non-reportable or non-actionable,\nand thus can be disregarded.\n\n## API\n### Types\nThe central type of the `result` library is the `Result\u003cS,F\u003e` interface, which\nis implemented by two package-scoped classes. All users of the library are\nexpected to create instances of the `Result` interface, initialized by the\nprovided static methods.\n\n### Static Methods\nThe `Result` interface presents two public static methods - `success` and\n`failure` - intended to create `Result` objects directly from plain Java\nobjects.\n\nThe `Result` interface also offers the static method `wrap`, which provides\nthe means to execute a computation and convert the return value (or any\npotential exceptions) into a `Result` object. The method is overloaded to\nsupport execution of the following computations: `BiFunction`, `BiPredicate`,\n`Function`, `Predicate`, and `Supplier`; along with a `Throwing` equivalent\nfor each one of the listed.\n\n### Methods\nThe `Result` interface defines a rich set of methods that can be used to\ncombine, compose, inspect, and process its state.\n\n#### Combine\nTODO\n\n#### Compose\nTODO\n\n#### Inspect\nTODO\n\n#### Process\nTODO\n\n## Inspiration\nThe `Result` type is heaving inspired by the `Either` monad from the standard\nlibrary of the Haskell language. Whilst the ideas in the `Either` class are of\ngreat value, the naming of `Left` and `Right` cases did not seem to bring\nforth the correct intuition and were thus renamed to `failure` and `success`,\nrespectively.\n\n## License\nThe `result` project is licensed under the terms of the [2-cause BSD\nlicense](LICENSE).\n\n## Author\nDaniel Lovasko \u003cdaniel.lovasko@gmail.com\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovasko%2Fresult","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flovasko%2Fresult","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovasko%2Fresult/lists"}